Check if Python Package is installed

前端 未结 16 1095
刺人心
刺人心 2020-12-02 05:59

What\'s a good way to check if a package is installed while within a Python script? I know it\'s easy from the interpreter, but I need to do it within a script.

I g

16条回答
  •  猫巷女王i
    2020-12-02 06:11

    You can use this:

    class myError(exception):
     pass # Or do some thing like this.
    try:
     import mymodule
    except ImportError as e:
     raise myError("error was occurred")
    

提交回复
热议问题