我正在尝试使用需求文件安装Python软件。
>> 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
所以我创建了一个虚拟环境
>> mkvirtualenv parser
(parser)
>> pip freeze
distribute==0.6.24
wsgiref==0.1.2
(parser)
>> pip install -r requirements.txt
...然后我下载了软件包但未安装,但出现错误:http://pastie.org/4079800
(parser)
>> pip freeze
distribute==0.6.24
wsgiref==0.1.2
令人惊讶的是,如果我尝试手动安装每个软件包,它们安装得很好。 例如:
>> 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
看起来
numexpr
包在安装时依赖于 numpy。 Pip 会两次通过您的要求:首先下载所有包并运行每个包的 setup.py
以获取其元数据,然后在第二次中安装所有包。
因此,numexpr 正在尝试在其 setup.py 中从 numpy 导入,但是当 pip 首次运行 numexpr 的 setup.py 时,它尚未安装 numpy。
这也是为什么你在逐个安装软件包时不会看到此错误的原因:如果你一次安装一个软件包,numpy 将在你之前完全安装在你的环境中
pip install
numexpr。
唯一的解决方案是在运行
pip install numpy
之前安装 pip install -r requirements.txt
- 您将无法使用单个requirements.txt 文件通过单个命令来完成此操作。
我遇到了类似的问题,最终得到以下结果:
cat requirements.txt | sed -e '/^\s*#.*$/d' -e '/^\s*$/d' | xargs -n 1 python -m pip install
这将逐行读取requirements.txt并执行pip。我无法找到从哪里得到正确的答案,所以对此表示歉意,但我在下面找到了一些理由:
希望这对替代方案有所帮助。
这有时很烦人,是 pip 的一个错误。 当您运行 pip install package_name 时,pip 将首先对目标包运行 pip check,并安装依赖项(目标包)所需的所有包。 但是当你运行 pip install -rrequirements.txt 时,pip 会尝试直接安装从上到下一一列出的所有必需的软件包。有时依赖项会列在它所依赖的包上方。
The solution is simple:
1.pip install package_name
2.simply put the error package to the bottom of the requirements.txt
3.sometimes a particular version of the package is not be able to be installed,just install the newest version of it and update the data in requirements.txt
您只需在文件名前添加./即可,例如:
pip install -r ./requirements.txt
然后就可以正确安装了。