[英]Pip installs packages in the wrong directory with virtualenv
With Python 3.7 on OS XI set up a virtual environment then在 OS XI 上使用 Python 3.7 设置一个虚拟环境,然后
$ source venv/bin/activate
$ pip install numpy
$ which pip
pip is /Users/me/PycharmProjects/Test1/venv/bin/pip
(venv)
But rather than installing in the virtual environment numpy
is installed in但不是在虚拟环境中安装numpy
而是安装在
/usr/local/lib/python2.7
and numpy
doesn't appear in pip list
并且numpy
没有出现在pip list
The issue occurs with both Python installed via the Python download or via brew
.通过 Python 下载或通过brew
安装的 Python 都会出现此问题。
What possible settings could be causing the package to be installed in the wrong location.哪些可能的设置可能导致软件包安装在错误的位置。
To answer my own question. 回答我自己的问题。
There was an invisible 有一个看不见的
~/.config/pip/pip.conf
file. 文件。 That contained these lines: 包含以下几行:
[global]
target = /usr/local/lib/python2.7/site-packages
This file was a few years old, so I'm unsure how it got there but removing it resolved the issue. 该文件已有几年历史了,所以我不确定它如何到达那里,但是删除它可以解决问题。
What worked for me :什么对我有用:
[global] [全球的]
target=D:\\Dropbox\\online store\\django\\ve\\lib\\site-packages目标=D:\\Dropbox\\在线商店\\django\\ve\\lib\\site-packages
3)after restarting venv, by using this command 3)重新启动venv后,使用此命令
python -m pip install <package name>
now I am able to install packages on my venv ( instead of being installed globally )现在我可以在我的 venv 上安装软件包(而不是全局安装)
I had this issue because I renamed the root directory of my project.我遇到了这个问题,因为我重命名了项目的根目录。 Looking at the venv/bin/activate
script, I could see references to the old name.查看venv/bin/activate
脚本,我可以看到对旧名称的引用。
Could probably fix it by hand, but I just deleted the venv folder and re-created it.可能可以手动修复它,但我只是删除了 venv 文件夹并重新创建了它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.