关于python 2.7:升级到ubuntu-16.10后,Pip不起作用

Pip does not work after upgrade to ubuntu-16.10

与pip一起运行命令会产生以下错误。即使命令 pip -V 也会产生以下错误。我了解到错误是由于安装工具版本31.0.0造成的,应该低于28.0.0。但我的安装工具版本是26.1.1,它仍然给出相同的错误。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Traceback (most recent call last):
  File"/usr/local/bin/pip", line 7, in
    from pip import main
  File"/usr/local/lib/python3.5/dist-packages/pip/__init__.py", line 26, in
    from pip.utils import get_installed_distributions, get_prog
  File"/usr/local/lib/python3.5/dist-packages/pip/utils/__init__.py", line 27, in
    from pip._vendor import pkg_resources
  File"/usr/local/lib/python3.5/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 3018, in
    @_call_aside
  File"/usr/local/lib/python3.5/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 3004, in _call_aside
    f(*args, **kwargs)
  File"/usr/local/lib/python3.5/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 3046, in _initialize_master_working_set
    dist.activate(replace=False)
  File"/usr/local/lib/python3.5/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 2578, in activate
    declare_namespace(pkg)
  File"/usr/local/lib/python3.5/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 2152, in declare_namespace
    _handle_ns(packageName, path_item)
  File"/usr/local/lib/python3.5/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 2092, in _handle_ns
    _rebuild_mod_path(path, packageName, module)
  File"/usr/local/lib/python3.5/dist-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'


我能找到的唯一解决方案是重新安装pip。在终端上运行这些命令

  • 埃多克斯1〔2〕
  • 埃多克斯1〔3〕
  • 小精灵

    然而,这只适用于pip,而不是pip3


    升级安装工具:
    wget https://bootstrap.pypa.io/ez_setup.py -O - | sudo python3

    一般来说,sudo和pip结合被认为是有害的,当你的系统还没有被破坏时,要避免这样做。


    请参阅https://stackoverflow.com/a/48126778/7596504。这个问题可以通过修改你的/usr/local/lib/python3.5/dist-packages/pip/_vendor/pkg_resources/__init__.py来解决。