升级到ubuntu-16.10后,Pip不起作用
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了升级到ubuntu-16.10后,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'
答案
我能找到的唯一解决方案是重新安装pip
。在终端上运行这些命令
wget https://bootstrap.pypa.io/get-pip.py
sudo -H python get-pip.py --prefix=/usr/local/
但是,这只适用于pip
,而不是pip3
!
另一答案
升级你的setuptools:
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
来解决这个问题。
以上是关于升级到ubuntu-16.10后,Pip不起作用的主要内容,如果未能解决你的问题,请参考以下文章