python - 为什么virtualenv上的`pip install`会引发“无法执行'--user'安装”?
问题描述
- 注意:这里的用户名
airflow
在所有以下命令中:
e.g. airflow@my-worker-0:~$ which python
我在我的 Debian GNU/Linux 10 机器(Airflow 服务器)上(全局)安装了 Python3.8:
$ which python
>> /usr/local/bin/python
$ python --version
>> Python 3.8.10
$ which pip
>> /usr/local/bin/pip
以下是关于 pip 的配置:
$ pip config list
:env:.user='true'
$ pip config list -v
Skipping file '/etc/xdg/pip/pip.conf' (variant: global)
Skipping file '/etc/pip.conf' (variant: global)
For variant 'user', will try loading '/home/airflow/.pip/pip.conf'
For variant 'user', will try loading '/home/airflow/.config/pip/pip.conf'
Skipping file '/usr/local/pip.conf' (variant: site)
:env:.user='true'
一件奇怪的事情是conf
上面的所有文件都不存在:
$ cat /home/airflow/.config/pip/pip.conf
>> bash: /home/airflow/.config/pip/pip.conf: No such file or directory
$ cat /etc/xdg/pip/pip.conf
>> cat: /etc/xdg/pip/pip.conf: No such file or directory
$ cat /etc/pip.conf
>> cat: /etc/pip.conf: No such file or directory
$ cat /home/airflow/.pip/pip.conf
>> cat: /home/airflow/.pip/pip.conf: No such file or directory
$ cat /home/airflow/.config/pip/pip.conf
>> cat: /home/airflow/.config/pip/pip.conf: No such file or directory
$ cat /usr/local/pip.conf
>> cat: /usr/local/pip.conf: No such file or directory
我创建virtualenv
并尝试安装 python 包,但出现错误:
$ virtualenv /tmp/apache-beam-venv-wow --python=python3.8
>> created virtual environment CPython3.8.10.final.0-64 in 243ms
creator CPython3Posix(dest=/tmp/apache-beam-venv-wow, clear=False, no_vcs_ignore=False, global=False)
seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/home/airflow/.local/share/virtualenv)
added seed packages: pip==21.1.3, setuptools==57.4.0, wheel==0.36.2
activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
$ ls -alh /tmp/apache-beam-venv-wow/
>> total 12K
drwxr-xr-x 4 airflow airflow 64 Aug 16 01:49 .
drwxrwxrwt 1 root root 4.0K Aug 16 02:24 ..
-rw-r--r-- 1 airflow airflow 40 Aug 16 01:03 .gitignore
drwxr-xr-x 2 airflow airflow 285 Aug 16 01:03 bin
drwxr-xr-x 3 airflow airflow 23 Aug 16 01:03 lib
-rw-r--r-- 1 airflow airflow 225 Aug 16 01:03 pyvenv.cfg
$ ls -alh /tmp/apache-beam-venv-wow/bin
>> total 56K
drwxr-xr-x 2 airflow airflow 285 Aug 16 01:03 .
drwxr-xr-x 4 airflow airflow 64 Aug 16 01:49 ..
-rw-r--r-- 1 airflow airflow 2.1K Aug 16 01:03 activate
-rw-r--r-- 1 airflow airflow 1.5K Aug 16 01:03 activate.csh
-rw-r--r-- 1 airflow airflow 3.0K Aug 16 01:03 activate.fish
-rw-r--r-- 1 airflow airflow 1.8K Aug 16 01:03 activate.ps1
-rw-r--r-- 1 airflow airflow 1.2K Aug 16 01:03 activate.xsh
-rw-r--r-- 1 airflow airflow 1.2K Aug 16 01:03 activate_this.py
-rwxr-xr-x 1 airflow airflow 245 Aug 16 01:03 pip
-rwxr-xr-x 1 airflow airflow 245 Aug 16 01:03 pip-3.8
-rwxr-xr-x 1 airflow airflow 245 Aug 16 01:03 pip3
-rwxr-xr-x 1 airflow airflow 245 Aug 16 01:03 pip3.8
lrwxrwxrwx 1 airflow airflow 21 Aug 16 01:03 python -> /usr/local/bin/python
lrwxrwxrwx 1 airflow airflow 6 Aug 16 01:03 python3 -> python
lrwxrwxrwx 1 airflow airflow 6 Aug 16 01:03 python3.8 -> python
-rwxr-xr-x 1 airflow airflow 232 Aug 16 01:03 wheel
-rwxr-xr-x 1 airflow airflow 232 Aug 16 01:03 wheel-3.8
-rwxr-xr-x 1 airflow airflow 232 Aug 16 01:03 wheel3
-rwxr-xr-x 1 airflow airflow 232 Aug 16 01:03 wheel3.8
$ /tmp/apache-beam-venv-wow/bin/pip install requests
>> ERROR: Can not perform a '--user' install. User site-packages are not visible in this virtualenv.
WARNING: You are using pip version 21.1.3; however, version 21.2.4 is available.
You should consider upgrading via the '/tmp/apache-beam-venv-wow/bin/python -m pip install --upgrade pip' command.
我pip config
也在这个 virtualenv 的 pip 上运行命令:
$ /tmp/apache-beam-venv-wow/bin/pip config list
>> :env:.user='true'
$ /tmp/apache-beam-venv-wow/bin/pip config list -v
>> Skipping file '/etc/xdg/pip/pip.conf' (variant: global)
Skipping file '/etc/pip.conf' (variant: global)
For variant 'user', will try loading '/home/airflow/.pip/pip.conf'
For variant 'user', will try loading '/home/airflow/.config/pip/pip.conf'
Skipping file '/tmp/apache-beam-venv-wow/pip.conf' (variant: site)
:env:.user='true'
我想知道为什么 virtualenv 的 pip 安装包使用--user
选项以及如何防止这种情况。
我试过的:
$ /tmp/apache-beam-venv-wow/bin/pip config get :env:.user
true
$ /tmp/apache-beam-venv-wow/bin/pip config set ':env:.user' false
Writing to /home/airflow/.config/pip/pip.conf
$ cat /home/airflow/.config/pip/pip.conf
[:env:]
user = false
$ ./pip install requests
ERROR: Can not perform a '--user' install. User site-packages are not visible in this virtualenv.
WARNING: You are using pip version 21.1.3; however, version 21.2.4 is available.
You should consider upgrading via the '/tmp/apache-beam-venv-wow/bin/python -m pip install --upgrade pip' command.
解决方案
this:
$ /tmp/apache-beam-venv-wow/bin/pip config list
>> :env:.user='true'
is indicating you have PIP_USER=1
set in your environment (perhaps due to a .bashrc
or /etc/environment
file?)
unset that and it should stop forcing --user
on your install commands (environment variables override the configuration files for pip)
unset PIP_USER
推荐阅读
- github - Github rest api post label 给出数组输入错误
- compiler-optimization - 如何通过正确的配置减少 tensorflow-lite 二进制文件的大小?
- javascript - 如何在点击时切换鼠标悬停事件?
- git - 在合并后执行 `git diff` 时避免写出最新的提交哈希
- c - Printf 未显示并返回值 3221225477
- c++ - Adafruit Fona 与 echo 服务器建立连接,但不发送任何数据
- excel - 如何解决我的代码给我一个编译错误的问题?
- java - Android Activity 不会自动出现在清单中?
- java - 替换字符串中的特定单词,给定单词所在索引的数组列表
- r - 无法在 R 3.3.0 上安装 data.table 包