Check if Python Package is installed

前端 未结 16 1063
刺人心
刺人心 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条回答
  •  一向
    一向 (楼主)
    2020-12-02 06:09

    Hmmm ... the closest I saw to a convenient answer was using the command line to try the import. But I prefer to even avoid that.

    How about 'pip freeze | grep pkgname'? I tried it and it works well. It also shows you the version it has and whether it is installed under version control (install) or editable (develop).

提交回复
热议问题