pip 无法从 requirements.txt 安装软件包
问题描述
我正在尝试使用需求文件安装 python 软件.
I am trying to install a python software using the requirements file.
>> cat requirements.txt
Cython==0.15.1
numpy==1.6.1
distribute==0.6.24
logilab-astng==0.23.1logilab-common==0.57.1
netaddr==0.7.6
numexpr==2.0.1
ply==2.5
pycallgraph==0.5.1
pyflowtools==0.3.4.1
pylint==0.25.1
tables==2.3.1
wsgiref==0.1.2
所以我创建了一个虚拟环境
So I create a virtual environment
>> mkvirtualenv parser
(parser)
>> pip freeze
distribute==0.6.24
wsgiref==0.1.2
(parser)
>> pip install -r requirements.txt
...然后我下载了包但没有安装错误:http://pastie.org/4079800
... and then I packages downloaded but not installed with errors: http://pastie.org/4079800
(parser)
>> pip freeze
distribute==0.6.24
wsgiref==0.1.2
令人惊讶的是,如果我尝试手动安装每个软件包,它们安装得很好.例如:
Surprisingly, if I try to manually install each package, they install just fine. For instance:
>> pip install numpy==1.6.1
(parser)
>> pip freeze
distribute==0.6.24
wsgiref==0.1.2
numpy==1.6.1
我迷路了.怎么回事?
PS:我正在使用 pip
v1.1 和 python
v2.7.2 与 virtualenv
和 virtualenvwrapper
PS: I am using pip
v1.1 and python
v2.7.2 with virtualenv
and virtualenvwrapper
解决方案
看起来 numexpr
包在安装时依赖于 numpy.Pip 两次通过您的要求:首先它下载所有包并运行每个包的 setup.py
以获取其元数据,然后在第二遍中安装它们.
It looks like the numexpr
package has an install-time dependency on numpy. Pip makes two passes through your requirements: first it downloads all packages and runs each one's setup.py
to get its metadata, and then it installs them all in a second pass.
所以,numexpr 是在它的 setup.py 中尝试从 numpy 导入,但是当 pip 第一次运行 numexpr 的 setup.py 时,它还没有安装 numpy.
So, numexpr is trying to import from numpy in its setup.py, but when pip first runs numexpr's setup.py, it has not yet installed numpy.
这也是你一个一个安装包时看不到这个错误的原因:如果你一次安装一个,numpy会在你pip install
数字表达式.
This is also why you don't see this error when you install the packages one by one: if you install them one at a time, numpy will be fully installed in your environment before you pip install
numexpr.
唯一的解决方案是在运行 pip install -r requirements.txt
之前安装 pip install numpy
- 你将无法在带有单个 requirements.txt 文件的单个命令.
The only solution is to install pip install numpy
before you ever run pip install -r requirements.txt
-- you won't be able to do this in a single command with a single requirements.txt file.
更多信息在这里:https://github.com/pypa/pip/issues/25
相关文章