无法在Debian上的虚拟环境中从“ pip._vendor”导入名称“ six”

时间:2020-06-10 10:20:32

标签: python python-3.x pip debian virtualenv

在Debian / Bullseye(测试)上,提供的python3从3.7移至3.8。

要向仍在使用它的项目提供3.7,我在用户区python3.7.7)中安装了一个全新的this way

现在我要使用它,让我们重新创建一个虚拟环境:

$ virtualenv --clear -p ~/pythonroot/bin/python3.7 .venv
created virtual environment CPython3.7.7.final.0-64 in 98ms
  creator CPython3Posix(dest=/home/user/git/repo/.venv, clear=True, global=False)
  seeder FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, pkg_resources=latest, via=copy, app_data_dir=/home/user/.local/share/virtualenv/seed-app-data/v1.0.1.debian)
  activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator

pip无法运行:

$ source .venv/bin/activate;pip -V
Traceback (most recent call last):
  File "/home/user/git/repo/.venv/bin/pip", line 5, in <module>
    from pip._internal.cli.main import main
  File "/home/user/git/repo/.venv/lib/python3.7/site-packages/pip/_internal/cli/main.py", line 10, in <module>
    from pip._internal.cli.autocompletion import autocomplete
  File "/home/user/git/repo/.venv/lib/python3.7/site-packages/pip/_internal/cli/autocompletion.py", line 9, in <module>
    from pip._internal.cli.main_parser import create_main_parser
  File "/home/user/git/repo/.venv/lib/python3.7/site-packages/pip/_internal/cli/main_parser.py", line 7, in <module>
    from pip._internal.cli import cmdoptions
  File "/home/user/git/repo/.venv/lib/python3.7/site-packages/pip/_internal/cli/cmdoptions.py", line 24, in <module>
    from pip._internal.cli.progress_bars import BAR_TYPES
  File "/home/user/git/repo/.venv/lib/python3.7/site-packages/pip/_internal/cli/progress_bars.py", line 7, in <module>
    from pip._vendor import six
ImportError: cannot import name 'six' from 'pip._vendor' (/home/user/git/repo/.venv/lib/python3.7/site-packages/pip/_vendor/__init__.py)
zsh: exit 1     pip -

再次使用显式pip版本重新创建虚拟环境:

$ deactivate
$ virtualenv --clear --pip 19 -p ~/pythonroot/bin/python3.7 .venv
created virtual environment CPython3.7.7.final.0-64 in 1380ms
  creator CPython3Posix(dest=/home/user/git/repo/.venv, clear=True, global=False)
  seeder FromAppData(download=False, pip=19, setuptools=latest, wheel=latest, pkg_resources=latest, via=copy, app_data_dir=/home/user/.local/share/virtualenv/seed-app-data/v1.0.1.debian)
  activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
$ source .venv/bin/activate;pip -V
pip 20.1.1 from /usr/lib/python3/dist-packages/pip (python 3.8)

现在pip运行。

问题:为什么使用的pip版本是我在创建虚拟环境时设置的另一个版本?


编辑:我编辑标题:这看起来像是路径问题…

我添加了python3.7安装系统范围

$ python3 -m pip -V
pip 20.1.1 from /usr/lib/python3/dist-packages/pip (python 3.8)
$ python3.7 -m pip -V
pip 19.2.3 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)
$ ./pylocal/bin/python3.7 -m pip -V
pip 19.2.3 from /home/user/pylocal/lib/python3.7/site-packages/pip (python 3.7)
$ python3 -c 'from pip._vendor import six'
$ python3.7 -c 'from pip._vendor import six'
$ ./pylocal/bin/python3.7 -c 'from pip._vendor import six'

但在虚拟环境中,pip仍然损坏:

$ virtualenv --clear --python python3.7 .venv37
created virtual environment CPython3.7.7.final.0-64 in 102ms
  creator CPython3Posix(dest=/home/user/.venv37, clear=True, global=False)
  seeder FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, pkg_resources=latest, via=copy, app_data_dir=/home/user/.local/share/virtualenv/seed-app-data/v1.0.1.debian)
  activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
$ source .venv37/bin/activate
(.venv37)$ which python
/home/user/.venv37/bin/python
(.venv37)$ python -V
Python 3.7.7
(.venv37)$ python -c 'from pip._vendor import six'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: cannot import name 'six' from 'pip._vendor' (/home/user/.venv37/lib/python3.7/site-packages/pip/_vendor/__init__.py)
zsh: exit 1     python -c 'from pip._vendor import six'

0 个答案:

没有答案