简体   繁体   English

pip 无法从 requirements.txt 安装包

[英]pip fails to install packages from requirements.txt

I am trying to install a python software using the requirements file.我正在尝试使用需求文件安装 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

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

... and then I packages downloaded but not installed with errors: http://pastie.org/4079800 ...然后我打包下载但没有安装错误: 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

I am lost.我搞不清楚了。 What is going on?到底是怎么回事?

PS: I am using pip v1.1 and python v2.7.2 with virtualenv and virtualenvwrapper PS:我正在使用带有virtualenvvirtualenvwrapper pip v1.1 和python v2.7.2

It looks like the numexpr package has an install-time dependency on numpy.看起来numexpr包对 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. Pip 对您的要求进行了两次传递:首先它下载所有包并运行每个包的setup.py以获取其元数据,然后在第二次传递中安装它们。

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.所以,numexpr 在它的 setup.py 中试图从 numpy 导入,但是当 pip 第一次运行 numexpr 的 setup.py 时,它还没有安装 numpy。

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 numexpr之前,numpy会完全安装在你的环境中。

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.唯一的解决方案是在运行pip install -r requirements.txt之前安装pip install numpy —— 您将无法使用单个 requirements.txt 文件在单个命令中执行此操作。

More info here: https://github.com/pypa/pip/issues/25更多信息在这里: https : //github.com/pypa/pip/issues/25

I come across with a similar issue and I ended up with the below:我遇到了类似的问题,结果如下:

cat requirements.txt | sed -e '/^\s*#.*$/d' -e '/^\s*$/d' | xargs -n 1 python -m pip install

That will read line by line the requirements.txt and execute pip.这将逐行读取 requirements.txt 并执行 pip。 I cannot find from where I got the answer properly, so apologies for that, but I found some justification below:我无法从哪里找到正确的答案,因此对此深表歉意,但我在下面找到了一些理由:

  1. How sed works: https://howto.lintel.in/truncate-empty-lines-using-sed/ sed 的工作原理: https : //howto.lintel.in/truncate-empty-lines-using-sed/
  2. Another similar answer but with git: https://stackoverflow.com/a/46494462/7127519另一个类似的答案,但使用 git: https : //stackoverflow.com/a/46494462/7127519

Hope this help with alternatives.希望这有助于替代方案。

This is quite annoying sometimes, a bug of pip.这有时很烦人,是 pip 的错误。 When you run pip install package_name the pip will first run pip check to the target package, and install all the required package for the dependency(target package).当您运行 pip install package_name 时,pip 将首先对目标包运行 pip check,并安装依赖项(目标包)所需的所有包。 But when you run pip install -r requirements.txt pip will try to directly install all the required packages listed one by one from top to bottom.但是当你运行 pip install -r requirements.txt 时,pip 会尝试直接安装所有需要的包,从上到下一一列出。 Sometimes the dependency is listed above the package it depend upon.有时依赖项列在它所依赖的包之上。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 pip 无法从 requirements.txt 中找到任何包 - pip fails to find any packages from requirements.txt 可以从requirements.txt递归地pip安装包 - Can pip install packages recursively from requirements.txt 解析 requirements.txt 并安装 requirements.txt 中指定的包是否与 pip install -r requirements.txt 相同? - Is parsing the requirements.txt and install packages specified in requirements.txt same as pip install -r requirements.txt? 为什么 pip install requirements.txt 安装额外的包? - Why does pip install requirements.txt install extra packages? 使用 pip 安装 requirements.txt - Install requirements.txt with pip 找不到`pip install -r requirements.txt`安装的软件包 - Packages installed by `pip install -r requirements.txt` are not found 在 docker build 中运行 pip install requirements.txt 失败 - Running pip install requirements.txt fails in docker build 如何根据本地目录中的 requirements.txt 文件使用 pip 安装软件包? - How can I install packages using pip according to the requirements.txt file from a local directory? 使用 requirements.txt 在新的 conda 环境中自动安装来自 conda 通道和 pip 的包 - using requirements.txt to automatically install packages from conda channels and pip in a new conda environment 使用Chef时,“ pip install -r requirements.txt”失败 - 'pip install -r requirements.txt' fails when using Chef
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM