编程语言
首页 > 编程语言> > python – pip3错误 – ‘_NamespacePath’对象没有属性’sort’

python – pip3错误 – ‘_NamespacePath’对象没有属性’sort’

作者:互联网

我试图通过pip3安装一个包,我收到了这个错误.我运行的每个pip / pip3命令都给我这个错误 –

alexg@hitbox:~$pip3 -V
Traceback (most recent call last):
  File "/usr/local/bin/pip3", line 7, in <module>
    from pip import main
  File "/home/alexg/.local/lib/python3.5/site-packages/pip/__init__.py", line 26, in <module>
    from pip.utils import get_installed_distributions, get_prog
  File "/home/alexg/.local/lib/python3.5/site-packages/pip/utils/__init__.py", line 27, in <module>
    from pip._vendor import pkg_resources
  File "/home/alexg/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3018, in <module>
    @_call_aside
  File "/home/alexg/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3004, in _call_aside
    f(*args, **kwargs)
  File "/home/alexg/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3046, in _initialize_master_working_set
    dist.activate(replace=False)
  File "/home/alexg/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2578, in activate
    declare_namespace(pkg)
  File "/home/alexg/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2152, in declare_namespace
    _handle_ns(packageName, path_item)
  File "/home/alexg/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2092, in _handle_ns
    _rebuild_mod_path(path, packageName, module)
  File "/home/alexg/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2121, in _rebuild_mod_path
    orig_path.sort(key=position_in_sys_path)
AttributeError: '_NamespacePath' object has no attribute 'sort'

我已经尝试根据一些答案运行pip3 install –upgrade pip setuptools,但每个pip命令都会给我错误.我被困住了,什么也做不了.

可能导致它的原因,以及如何解决这个问题?

我使用Python 3.5.2在Ubuntu 16.04上

解决方法:

我遇到了与python 3.5.2和pip3(9.0.1)相同的问题.我通过以下解决方法修复了它:https://github.com/pypa/setuptools/issues/885#issuecomment-307696027

更具体地说,我编辑了这个文件的第2121~212行:“sudo vim /usr/local/lib/python3.5/dist-packages/pip/_vendor/pkg_resources/__init__.py”

#orig_path.sort(key=position_in_sys_path)
#module.__path__[:] = [_normalize_cached(p) for p in orig_path]
orig_path_t = list(orig_path)
orig_path_t.sort(key=position_in_sys_path)
module.__path__[:] = [_normalize_cached(p) for p in orig_path_t]

标签:python-3-5,attributeerror,python,pip
来源: https://codeday.me/bug/20190928/1826970.html