[英]Pip installing packages to global site-packages when inside virtual environment
Let me preface this by stating that I have read pip installing in global site-packages instead of virtualenv and it did not solve my problem. 首先,让我指出我已经阅读了在全局站点软件包中而不是virtualenv中安装pip的方法 ,但这并不能解决我的问题。
When creating a virtual environment using python -m venv venv
(or any other name) and then activating said venv using source venv/bin/activate
, running pip install [package]
actually installs the package to the (user) global python site packages, located in ~/.local/lib/python3.7/site-packages/
. 当使用python -m venv venv
(或任何其他名称)创建虚拟环境,然后使用source venv/bin/activate
激活所述venv时,运行pip install [package]
实际上会将软件包安装到(用户)全局python站点软件包,位于~/.local/lib/python3.7/site-packages/
。
Interestingly, it always tries to install the packages and does not recognize that they are installed globally, meaning it is looking for packages initially in the correct location. 有趣的是,它始终尝试安装软件包,并且无法识别它们是全局安装的,这意味着它最初在正确的位置寻找软件包。
I am running Manjaro Linux, and running the latest updates. 我正在运行Manjaro Linux,并正在运行最新更新。
I created this virtual environment in ~/Stuff/tests/venv
. 我在~/Stuff/tests/venv
创建了这个虚拟环境。 Running which pip
and which python
returns: 运行which pip
和which python
返回:
(venv) angelin@asgard:~/Stuff/tests/venv $ which pip
/home/angelin/Stuff/tests/venv/bin/pip
(venv) angelin@asgard:~/Stuff/tests/venv $ which python
/home/angelin/Stuff/tests/venv/bin/python
Checking said pip executable shows the correct shebang: 检查说的pip可执行文件显示正确的shebang:
(venv) angelin@asgard:~/Stuff/tests/venv $ cat bin/pip
#!/home/angelin/Stuff/tests/venv/bin/python
# -*- coding: utf-8 -*-
...
My path, when inside the virtualenv, points to the virtual environment first, too: 在virtualenv中时,我的路径也首先指向虚拟环境:
(venv) angelin@asgard:~/Stuff/tests/venv $ echo $PATH
/home/angelin/Stuff/tests/venv/bin:/home/angelin/.local/bin:...
Manually running python -m pip
or venv/bin/python venv/bin/pip
produces the same results. 手动运行python -m pip
或venv/bin/python venv/bin/pip
会产生相同的结果。
The PYTHONPATH
variable is not set. 未设置PYTHONPATH
变量。
I have tried reinstalling python and pip using pacman -S python python-pip
, but I believe that only reinstalls the global package (located in /usr/bin
and I didn't want to mess with the .local
install in case I broke something even more than it is. 我尝试使用pacman -S python python-pip
重新安装python和pip,但是我相信只重新安装全局软件包(位于/usr/bin
,我不想弄乱.local
安装,以防万一我破坏了某些东西甚至更多。
Any advice is appreciated. 任何建议表示赞赏。
I have a temporary workaround in place. 我有一个临时的解决方法。
/etc/pip.conf
contained: /etc/pip.conf
包含:
[global]
user = true
There was no local pip config file, this was causing it to always pass the --user
option. 没有本地pip配置文件,这导致它始终通过--user
选项。 I am not sure how to configure my local file correctly, but I created it and set user = false
and will just manually pass the --user
option outside of venvs. 我不确定如何正确配置本地文件,但是我创建了本地文件并将其设置为user = false
并且只会在venvs之外手动传递--user
选项。
This doesn't feel like a proper fix, as it was working normally 2 days ago and the global file hasn't been changed in more than a month. 感觉这不是一个适当的修复程序,因为它在2天前可以正常工作,并且一个月以来没有更改全局文件。 Maybe an update broke something, who knows. 谁知道,也许更新会破坏某些东西。 If anyone else has a better solution, feel free to share. 如果其他人有更好的解决方案,请随时分享。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.