python - Pip 安装在 Virtualenv 中工作,但*不*与 `-r requirements.txt` 一起工作

标签 python pip installation virtualenv requirements.txt

我遇到了在 here 等答案中讨论的记录良好的 Virtualenv-Pip 错误的独特版本和 here .在这些情况下,问题是 pip 安装在全局文件夹中,在某些情况下是因为其中一个 pip 脚本中的 shebang 是错误的,在其他情况下是因为 bin/activate 中的第 42 行。脚本错误,但它总是全局安装。

我的问题不同:在我的虚拟环境中 pip install <package>按需工作(本地安装),但 pip install -r requirements.txt安装到虚空例如:

pip install scipy

然后查看/home/user/software/project/venv/lib/python3.6/site-packages的内容我得到结果:

easy_install.py  
numpy  
numpy-1.16.1.dist-info  
pip  
pip-19.0.2.dist-info  
pkg_resources  
__pycache__  
scipy  
scipy-1.2.1.dist-info  
setuptools  
setuptools-40.8.0.dist-info  
wheel  
wheel-0.33.0.dist-info

但是,当在同一个虚拟环境中时,我运行 pip install -r requirements.txt , 其中requirements.txt要求安装 numpy、Cython、sklearn、matplotlib 和 argparse,并输出:

Collecting Cython (from -r requirements.txt (line 1))                                                                                                                                                              
  Downloading https://files.pythonhosted.org/packages/16/98/49aa24054e99e9c7734e49d6996662f547e4e2faae0051d35fbbc461afa4/Cython-0.29.5-cp36-cp36m-manylinux1_x86_64.whl (2.1MB)                                    
    100% |████████████████████████████████| 2.1MB 23.6MB/s                                                                                                                                                         
Collecting numpy (from -r requirements.txt (line 2))                                                                                                                                                               
  Using cached https://files.pythonhosted.org/packages/f5/bf/4981bcbee43934f0adb8f764a1e70ab0ee5a448f6505bd04a87a2fda2a8b/numpy-1.16.1-cp36-cp36m-manylinux1_x86_64.whl                                            
Collecting sklearn (from -r requirements.txt (line 3))                                                                                                                                                             
  Downloading https://files.pythonhosted.org/packages/1e/7a/dbb3be0ce9bd5c8b7e3d87328e79063f8b263b2b1bfa4774cb1147bfcd3f/sklearn-0.0.tar.gz
Collecting matplotlib (from -r requirements.txt (line 4))
  Downloading https://files.pythonhosted.org/packages/71/07/16d781df15be30df4acfd536c479268f1208b2dfbc91e9ca5d92c9caf673/matplotlib-3.0.2-cp36-cp36m-manylinux1_x86_64.whl (12.9MB)
    100% |████████████████████████████████| 12.9MB 6.3MB/s
Collecting argparse (from -r requirements.txt (line 5))
  Downloading https://files.pythonhosted.org/packages/f2/94/3af39d34be01a24a6e65433d19e107099374224905f1e0cc6bbe1fd22a2f/argparse-1.4.0-py2.py3-none-any.whl

这不会导致向本地站 pip 包添加任何新内容。更重要的是,当我尝试查看它们的安装位置时,没有 site-packages /usr/lib/python2.7 中的目录, /usr/local/lib/python2.7 , /usr/lib/python3 , /usr/lib/python3.6 , usr/lib/python3.7 , ~/.local/lib/python3.6/ , 或 ~/.local/lib/python2.7/ .

为了验证这一 pip ,当我运行时: find /usr/ -name "Cython" 我得到一个空的结果。

有什么建议吗?我可以编写一个字面上调用 pip install 的 bash 脚本相反,但这看起来太草率了,我觉得我应该在它变得更糟之前解决它。

注意事项:

我的机器在 18.04.1 上,它有 python3.6.7 作为 python3和 python 2.7.15 作为 python2作为机器默认安装,我安装了pip对于sudo apt install python-pipsudo apt install python3-pip , 这个虚拟环境是用 virtualenv -p python3 venv 创建的

我的 requirements.txt :

Cython
numpy
sklearn
matplotlib
torch>=0.4.1
torchvision>=0.2.1
argparse
quadprog

Full output from pip install -r requirements.txt

最佳答案

所以这是一个部分答案,但我至少弄清楚了问题,即使我不完全理解为什么。当我改变时:

virtualenv -p python3 venv

virtualenv -p/usr/lib/python3.6 venv .

pip install -r requirements.txt 有效,生成了正确的站 pip 包。

同样,我不知道为什么会这样,但确实如此。我只是用不同的 python 版本再次尝试,但运气不太好,所以我不完全确定这是否是一个通用修复程序。当我有更好的解释时,我会编辑这个答案。

关于python - Pip 安装在 Virtualenv 中工作,但*不*与 `-r requirements.txt` 一起工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54682067/

相关文章:

database - 在 ubuntu 上安装 oracle 10g xe。登录和创建数据库的问题

python - 如何在 numpy 数组中存储不同大小的数组列表(用于集群目的)?

python - 具有特殊规则的 Pandas agg 数组

python - OpenCV安装: deprecation error

python - 如何在 django 中使用 HTMLParser 的另一个模块位置

python - pypi:如何检查包是否正在使用 wheel

c# - 使用 mysql c# 创建安装程序包

python - 将文件读入字典python

python - 字符编码

深度学习环境下Python包安装错误