我使用的是 Ubuntu 16.04,在使用 pip3 时遇到了问题。具体来说,当我尝试通过以下方式卸载软件包时
sudo pip3 uninstall
我遇到了
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import main
ImportError: cannot import name 'main'
我尝试通过重新安装 pip3 来解决这个问题,具体来说
sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall
成功了。但是,我根本没有本地版本的 pip3
bash: /home/kurt/.local/bin/pip3: No such file or directory
which pip3
在新的终端中使用我发现
$ which pip3
/usr/bin/pip3
尝试使用 pip3 会让我
$ pip3
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)
ImportError: No module named 'pip._vendor.pkg_resources'
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 13, in <module>
from pip.exceptions import InstallationError, CommandError, PipError
File "/usr/lib/python3/dist-packages/pip/exceptions.py", line 6, in <module>
from pip._vendor.six import iteritems
File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", line 75, in <module>
vendored("pkg_resources")
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 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
File "<frozen importlib._bootstrap>", line 634, in _load_backward_compatible
File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2927, in <module>
File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2913, in _call_aside
File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2952, in _initialize_master_working_set
File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 956, in subscribe
File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2952, in <lambda>
File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2515, in activate
File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2097, in declare_namespace
File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2047, in _handle_ns
File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2066, in _rebuild_mod_path
AttributeError: '_NamespacePath' object has no attribute 'sort'
但是,我在输入时可以顺利执行sudo -H pip3 -v
。从 apt 重新安装 pip3,例如
sudo apt-get install python3-pip --reinstall
没有效果。如果有人有任何见解,或者遇到过类似的问题,我将非常感激任何关于如何解决此问题的意见。
答案1
使用以下方法卸载 pip3 后
sudo apt-get remove python3-pip
我删除了目录
$HOME/.local/lib/python3.5/site-pacakges
并使用 apt-get 重新安装 pip3
sudo apt-get install python3-pip
pip3
这似乎解决了问题。尝试使用或时,我不再收到上述错误sudo pip3
。相反,pip3 -V
、sudo pip3 -V
和sudo -H pip3 -V
都完全相同且成功返回
pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5)