在虚拟环境中时,将安装程序包安装到全局站点程序包 [英] Pip installing packages to global site-packages when inside virtual environment

查看:220
本文介绍了在虚拟环境中时,将安装程序包安装到全局站点程序包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请先声明我已阅读在全局站点软件包中而不是virtualenv中进行pip安装,但这并不能解决我的问题.

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.

使用python -m venv venv(或任何其他名称)创建虚拟环境,然后使用source venv/bin/activate激活所述venv时,运行pip install [package]实际上会将软件包安装到位于.

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/.

有趣的是,它始终尝试安装软件包,并且无法识别它们是全局安装的,这意味着它最初是在正确的位置寻找软件包.

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.

我正在运行Manjaro Linux,并正在运行最新更新.

I am running Manjaro Linux, and running the latest updates.

我在~/Stuff/tests/venv中创建了这个虚拟环境. 运行which pipwhich python会返回:

I created this virtual environment in ~/Stuff/tests/venv. Running which pip and which python returns:

(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

检查所述pip可执行文件显示正确的shebang:

Checking said pip executable shows the correct shebang:

(venv) angelin@asgard:~/Stuff/tests/venv $ cat bin/pip
#!/home/angelin/Stuff/tests/venv/bin/python
# -*- coding: utf-8 -*-
...

在virtualenv内时,我的路径也首先指向虚拟环境:

My path, when inside the virtualenv, points to the virtual environment first, too:

(venv) angelin@asgard:~/Stuff/tests/venv $ echo $PATH
/home/angelin/Stuff/tests/venv/bin:/home/angelin/.local/bin:...

手动运行python -m pipvenv/bin/python venv/bin/pip会产生相同的结果.
PYTHONPATH变量未设置.
我尝试使用pacman -S python python-pip重新安装python和pip,但我相信只重新安装全局软件包(位于/usr/bin中,我不想弄乱.local安装,以防万一我破坏了更多东西.是.

Manually running python -m pip or venv/bin/python venv/bin/pip produces the same results.
The PYTHONPATH variable is not set.
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.

任何建议都值得赞赏.

推荐答案

我有一个临时的解决方法.

I have a temporary workaround in place.

/etc/pip.conf包含:

[global]
user = true

没有本地pip配置文件,这导致它始终通过--user选项.我不确定如何正确配置本地文件,但是我创建了该文件并设置了user = false,并且只会在venvs之外手动传递--user选项.

There was no local pip config file, this was causing it to always pass the --user option. 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.

这感觉不是一个正确的解决方案,因为它在2天前可以正常工作,并且一个月以来没有更改全局文件.谁知道,也许更新会破坏某些东西.如果还有其他人有更好的解决方案,请随时分享.

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. Maybe an update broke something, who knows. If anyone else has a better solution, feel free to share.

这篇关于在虚拟环境中时,将安装程序包安装到全局站点程序包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆