【发布时间】:2019-07-07 23:42:30
【问题描述】:
我遇到了在here 和here 等答案中讨论的有据可查的Virtualenv-Pip 错误的独特版本。在这些情况下,问题是 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
这不会导致本地站点包中没有新的添加。更重要的是,当我尝试查看它们的安装位置时,/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/ 中没有site-packages 目录。
为了验证这一点,当我运行时:
find /usr/ -name "Cython"
我得到一个空的结果。
有什么建议吗?我可以编写一个 bash 脚本,直接调用 pip install,但这似乎很草率,我觉得我应该在它变得更糟之前解决这个问题。
注意事项:
我的机器在 18.04.1 上,它的 python3.6.7 为 python3 和 python 2.7.15 为 python2 作为机器默认安装,我为 sudo apt install python-pip 和 sudo apt install python3-pip 安装了 pip,这个虚拟环境是用virtualenv -p python3 venv创建的
我的requirements.txt:
Cython
numpy
sklearn
matplotlib
torch>=0.4.1
torchvision>=0.2.1
argparse
quadprog
【问题讨论】:
-
您可以将您的
requirements.txt添加到问题中吗? -
另外,除了收集之外,完整的
pip输出? -
添加手动
pip安装其余部分时会发生什么?Cython、sklearn、matplotlib和argparse? -
添加我的
requirements.txt和完整的pip输出。当我手动安装其余部分时,它们正常工作并且位于正确的站点包区域中。 -
另外,澄清一下,
18.04.1,你的意思是 Ubuntu?
标签: python pip installation virtualenv requirements.txt