升级到ubuntu-16.10后,Pip不起作用

时间:2017-02-12 06:18:58

标签: python-2.7 python-3.x ubuntu pip

与pip一起运行命令会出现以下错误。甚至命令 pip -V 也会产生以下错误。
我读到错误是由于setuptools版本31.0.0,它应该低于28.0.0。但我的setuptools的版本是26.1.1,它仍然给出相同的错误。

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'

3 个答案:

答案 0 :(得分:2)

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

  • pip
  • wget https://bootstrap.pypa.io/get-pip.py

但是,这仅适用于sudo -H python get-pip.py --prefix=/usr/local/,而不适用于pip

答案 1 :(得分:1)

升级您的setuptools: wget https://bootstrap.pypa.io/ez_setup.py -O - | sudo python3

通常sudo与pip相结合被认为是有害的,当你的系统尚未破坏时,请避免这种情况。

答案 2 :(得分:0)

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