我正在使用以下requirements.txt
文件在Ubuntu 12.04中安装几个Python包:
numpy>=1.8.2,<2.0.0
matplotlib>=1.3.1,<2.0.0
scipy>=0.14.0,<1.0.0
astroML>=0.2,<1.0
scikit-learn>=0.14.1,<1.0.0
rpy2>=2.4.3,<3.0.0
这两个命令:
$ pip install --download=/tmp -r requirements.txt
$ pip install --user --no-index --find-links=/tmp -r requirements.txt
(第一个下载包,第二个安装包)。
进程经常因以下错误而停止:
Could not find a version that satisfies the requirement <package> (from matplotlib<2.0.0,>=1.3.1->-r requirements.txt (line 2)) (from versions: )
No matching distribution found for <package> (from matplotlib<2.0.0,>=1.3.1->-r requirements.txt (line 2))
我手动修复:
pip install --user <package>
然后再次运行第二个pip install
命令。
但这只适用于特定的包。当我再次运行第二个pip install
命令时,该进程现在停止,并抱怨另一个必需的包,我需要再次重复该过程,即:手动安装新的必需包(使用上面的命令),然后运行第二个pip install
命令。
到目前为止,我不得不手动安装six
、pytz
、nose
,现在它抱怨需要mock
。
有没有办法告诉pip
自动安装所有需要的依赖项,这样我就不必一个接一个地手动安装?
添加:这只发生在Ubuntu 12.04 BTW中。在Ubuntu 14.04中,应用于requirements.txt
文件的pip install
命令可以正常工作。
经过两个小时的搜索,我找到了一种方法,只需一行命令就可以修复它。您需要知道包的版本(只需搜索包版本)。
命令:
我已经安装了python3,但是/usr/bin/python中的python仍然是旧的2.7版本
这起作用(
<pkg>
在我的例子中是pyserial
):python3 -m pip install <pkg>
这种方法(在目录中具有所有依赖项,而不是从索引下载)仅在目录包含所有包时才有效。因此,目录应该包含所有依赖项,但也包含那些依赖项所依赖的所有包(例如,
six
,pytz
等)。因此,您应该手动将它们包含在
requirements.txt
(以便第一步显式下载它们)中,或者您应该使用PyPI安装所有包,然后pip freeze > requirements.txt
来存储所需的所有包的列表。相关问题 更多 >
编程相关推荐