2011-06-23 93 views
16

我使用的命令皮普安装-r继续失败

pip install -r requirements.txt 

有时它没有安装软件包无论出于何种原因安装与PIP-Python包的列表,过去安装。即使出现这些故障,是否有可能继续使用下一个软件包?

回答

10

你可以写一个小包装脚本调用反复点子,是这样的:

#!/usr/bin/env python 
""" 
pipreqs.py: run ``pip install`` iteratively over a requirements file. 
""" 
def main(argv): 
    try: 
     filename = argv.pop(0) 
    except IndexError: 
     print("usage: pipreqs.py REQ_FILE [PIP_ARGS]") 
    else: 
     import pip 
     retcode = 0 
     with open(filename, 'r') as f: 
      for line in f: 
       pipcode = pip.main(['install', line.strip()] + argv) 
       retcode = retcode or pipcode 
     return retcode 
if __name__ == '__main__': 
    import sys 
    sys.exit(main(sys.argv[1:])) 

,你可以调用像pipreqs.py requirements.txt --some --other --pip --args

请注意,这只适用于“继续尽管失败”的座右铭深度---如果pip无法安装列出的某项子要求,那么当然父要求仍然会失败。

+0

谢谢,这似乎工作。尽管如此,还是有一个令人讨厌的副作用:来自pip的日志消息似乎重复(并且一式三份等),在需求文件中列出的软件包越多。这可能是一个记录器实例化问题。 – dangonfast

25

我有同样的问题。 继续上@格雷格哈斯金斯线,也许这个庆典一行代码更加简洁:

cat requirements.txt | while read PACKAGE; do pip install "$PACKAGE"; done 

# TODO: extend to make the script print a list of failed installs, 
# so we can retry them. 

(对于非shellscripters:调用pip install每个列出的软件包)的

相同注意关于失效的失败在这里适用!