【问题标题】:Install multiple packages simultaneously同时安装多个包
【发布时间】:2018-01-16 09:08:42
【问题描述】:

我正在 brew_installing 以下软件包

cmds = ['brew install ghostscript',
 'brew install imagemagick',
 'brew install libmagic',
 'pip install sphinx']
 for cmd in cmds:
     os.system(cmd)

命令一一运行。
如何同时运行四个命令?

【问题讨论】:

  • 你可以试试brew install ghostscript,imagemagick,libmagic

标签: python macos homebrew


【解决方案1】:

brew 允许您安装多个公式,如果您用空格分隔它们。

将您的公式指定为列表;

formulae = ['ghostscript', 'imagemagik', ...]

现在,用str.join 加入这些列表元素并将其传递给os.system -

import os
os.system("brew install {}".format(" ".join(formulae)))

但是,这对pip 命令没有帮助。对我们来说幸运的是,pip 不需要通过 os.system 调用。导入模块并调用pip.main

import pip
pip.main(['install', 'sphinx'])

这仍然意味着运行两个命令,但两个比四个好。

【讨论】:

    【解决方案2】:

    为了使 Coldspeed 答案中的最后一个建议更清楚:

    import pip
    
    for each in ["ghostscript","imagemagick","libmagic","sphinx"]: 
        pip.main(['install', each])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-10
      • 2018-08-10
      • 1970-01-01
      • 2018-05-02
      • 2015-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多