我正在 brew_installing 以下软件包
cmds = ['brew install ghostscript',
'brew install imagemagick',
'brew install libmagic',
'pip install sphinx']
for cmd in cmds:
os.system(cmd)
命令一条一条运行。
如何同时运行四个命令?
请您参考如下方法:
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'])
这仍然意味着运行两个命令,但两个总比四个好。
