我正在使用以下 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
命令。
So far I’ve had to manually install six
, pytz
, nose
, and now it’s complaining about mock
.
有没有办法告诉 pip
自动安装 所有 需要的依赖项,这样我就不必一个一个手动完成?
添加:这只发生在 Ubuntu 12.04 BTW 中。在 Ubuntu 14.04 中,应用于 requirements.txt
文件的 pip install
命令可以正常工作。
原文由 Gabriel 发布,翻译遵循 CC BY-SA 4.0 许可协议
这种方法(将所有依赖项都放在一个目录中,而不是从索引中下载)仅在目录包含所有包时才有效。因此,该目录应该包含所有依赖项以及这些依赖项所依赖的所有包(例如,
six
、pytz
等)。因此,您应该手动将这些包含在
requirements.txt
中(以便第一步明确下载它们),或者您应该使用 PyPI 安装所有包,然后pip freeze > requirements.txt
以存储所需的所有包的列表。