【发布时间】:2021-08-16 02:35:19
【问题描述】:
- 注意:这里的用户名是
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.
我也在这个 virtualenv 的 pip 上运行 pip config 命令:
$ /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.
【问题讨论】:
-
是否存在权限问题?你试过以
sudo运行吗? -
@ObsidianAge 不幸的是,我没有运行 sudo 命令的权限
-
这听起来像是问题所在。如果您不是 sudoer,您将无法在
/tmp中运行。尝试将其交换到您的主目录。 -
那是什么:
:env:.user='true'??? -
你能试试
echo $PIP_USER和set | grep -Fi user吗???
标签: python pip virtualenv