ModuleNotFoundError:没有名为“pip._vendor.distro”的模块

ModuleNotFoundError:没有名为“pip._vendor.distro”的模块

我一直在试图找出导致此错误的原因,但是我尝试过的每一个解决方案,从完全卸载 python 和 pip 到 rm-ing 某些文件夹都不起作用:

系统信息:Ubuntu 18.04.4 LTS(GNU/Linux 4.15.0-88-generic x86_64)

python3 -V:Python 3.6.9

$ pip3 install -R requirements.txt 
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", line 33, in vendored
    __import__(vendored_name, globals(), locals(), level=0)
ModuleNotFoundError: No module named 'pip._vendor.distro'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/pip3", line 9, in <module>
    from pip import main
  File "/usr/lib/python3/dist-packages/pip/__init__.py", line 22, in <module>
    from pip._vendor.requests.packages.urllib3.exceptions import DependencyWarning
  File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", line 67, in <module>
    vendored("distro")
  File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", line 36, in vendored
    __import__(modulename, globals(), locals(), level=0)
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 656, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible
  File "/usr/share/python-wheels/distro-1.0.1-py2.py3-none-any.whl/distro.py", line 1051, in <module>
  File "/usr/share/python-wheels/distro-1.0.1-py2.py3-none-any.whl/distro.py", line 595, in __init__
  File "/usr/share/python-wheels/distro-1.0.1-py2.py3-none-any.whl/distro.py", line 932, in _get_lsb_release_info
subprocess.CalledProcessError: Command 'lsb_release -a' returned non-zero exit status 1.

我试图确保 pip:

python3.8 -m ensurepip
Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 193, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/usr/lib/python3.8/ensurepip/__main__.py", line 5, in <module>
    sys.exit(ensurepip._main())
  File "/usr/lib/python3.8/ensurepip/__init__.py", line 200, in _main
    return _bootstrap(
  File "/usr/lib/python3.8/ensurepip/__init__.py", line 119, in _bootstrap
    return _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
  File "/usr/lib/python3.8/ensurepip/__init__.py", line 27, in _run_pip
    import pip._internal
  File "<frozen zipimport>", line 259, in load_module
  File "/tmp/tmp7_mor_ds/pip-19.2.3-py2.py3-none-any.whl/pip/_internal/__init__.py", line 40, in <module>
  File "<frozen zipimport>", line 259, in load_module
  File "/tmp/tmp7_mor_ds/pip-19.2.3-py2.py3-none-any.whl/pip/_internal/cli/autocompletion.py", line 8, in <module>
  File "<frozen zipimport>", line 259, in load_module
  File "/tmp/tmp7_mor_ds/pip-19.2.3-py2.py3-none-any.whl/pip/_internal/cli/main_parser.py", line 7, in <module>
  File "<frozen zipimport>", line 259, in load_module
  File "/tmp/tmp7_mor_ds/pip-19.2.3-py2.py3-none-any.whl/pip/_internal/cli/cmdoptions.py", line 15, in <module>
ModuleNotFoundError: No module named 'distutils'

然后尝试安装 distutils:

trever@server:~$ sudo apt install python3.8-distutils
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  python3.8-lib2to3
The following NEW packages will be installed:
  python3.8-distutils python3.8-lib2to3
0 upgraded, 2 newly installed, 0 to remove and 27 not upgraded.
Need to get 0 B/314 kB of archives.
After this operation, 1,235 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
(Reading database ... 194796 files and directories currently installed.)
Preparing to unpack .../python3.8-lib2to3_3.8.0-1+bionic2_all.deb ...
Unpacking python3.8-lib2to3 (3.8.0-1+bionic2) ...
dpkg: error processing archive /var/cache/apt/archives/python3.8-lib2to3_3.8.0-1+bionic2_all.deb (--unpack):
 trying to overwrite '/usr/lib/python3.8/lib2to3/Grammar.txt', which is also in package python3-lib2to3 3.6.9-1~18.04
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Preparing to unpack .../python3.8-distutils_3.8.0-1+bionic2_all.deb ...
Unpacking python3.8-distutils (3.8.0-1+bionic2) ...
dpkg: error processing archive /var/cache/apt/archives/python3.8-distutils_3.8.0-1+bionic2_all.deb (--unpack):
 trying to overwrite '/usr/lib/python3.8/distutils/README', which is also in package python3-distutils 3.6.9-1~18.04
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Errors were encountered while processing:
 /var/cache/apt/archives/python3.8-lib2to3_3.8.0-1+bionic2_all.deb
 /var/cache/apt/archives/python3.8-distutils_3.8.0-1+bionic2_all.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

我甚至无法删除/重新安装它:

trever@server:/usr/lib/python3.8$ sudo apt --fix-broken install
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... Done
The following additional packages will be installed:
  python
Suggested packages:
  python-doc python-tk
The following NEW packages will be installed:
  python
0 upgraded, 1 newly installed, 0 to remove and 27 not upgraded.
7 not fully installed or removed.
Need to get 0 B/140 kB of archives.
After this operation, 639 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Setting up python2.7-minimal (2.7.17-1~18.04) ...
Could not find platform independent libraries <prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
/usr/bin/python2.7: can't open file '/usr/lib/python2.7/py_compile.py': [Errno 2] No such file or directory
dpkg: error processing package python2.7-minimal (--configure):
 installed python2.7-minimal package post-installation script subprocess returned error exit status 2
dpkg: dependency problems prevent configuration of python-minimal:
 python-minimal depends on python2.7-minimal (>= 2.7.15~rc1-1~); however:
  Package python2.7-minimal is not configured yet.

dpkg: error processing package python-minimal (--configure):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 python2.7-minimal
 python-minimal
E: Sub-process /usr/bin/dpkg returned an error code (1)

答案1

rm -rf /usr/lib/python3.7/site-packages

python3.7 -m 确保pip

pip 安装--升级 pip

您需要删除 pip 包,而不是 site-packages 中所有已安装的包

答案2

看来我的主目录中的 python 已损坏。

因为我有 anaconda 环境,

我只是使用以下命令将其从我的用户目录中删除:

rm -rf /home/myusername/.local/lib/python3.6/

然后pip在某些 anaconda 环境中运行将解析为 anaconda 环境中的 pip。

相关内容