在运行脚本时安装软件包和插件 - Python?

时间:2012-07-23 17:37:58

标签: python installer

我见过许多GUI应用程序,在启动时,检查系统是否有某些软件包和插件,如果它们不存在,它会自动安装它们。在python中启动之前,如何使用我的GUI呢?我可以在.sh脚本或某种控制台脚本中执行此操作吗?

1 个答案:

答案 0 :(得分:1)

来自https://stackoverflow.com/a/4529027/1413321

from pkg_resources import WorkingSet , DistributionNotFound
working_set = WorkingSet()

# Printing all installed modules
print tuple(working_set)

# Detecting if module is installed
try:
    dep = working_set.require('paramiko>=1.0')
except DistributionNotFound:
    pass

# Installing it (anyone knows a better way?)
from setuptools.command.easy_install import main as install
install(['django>=1.2'])