本文主要是介绍Python AttributeError: '_NamespacePath' object has no attribute 'sort',希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
____tz_zs
问题:
在使用源码安装的方式版本回退一个三方包后,使用 pip
命令时,均会出现以下报错
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 mainFile "/usr/lib/python3/dist-packages/pip/__init__.py", line 13, in <module>from pip.exceptions import InstallationError, CommandError, PipErrorFile "/usr/lib/python3/dist-packages/pip/exceptions.py", line 6, in <module>from pip._vendor.six import iteritemsFile "/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_loadFile "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlockedFile "<frozen importlib._bootstrap>", line 664, in _load_unlockedFile "<frozen importlib._bootstrap>", line 634, in _load_backward_compatibleFile "/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_asideFile "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2952, in _initialize_master_working_setFile "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 956, in subscribeFile "/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 activateFile "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2097, in declare_namespaceFile "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2047, in _handle_nsFile "/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'
解决方案:
这意味着依赖关系混乱了,尝试了 pip3 install --upgrade setuptools
等一些方法,未能处理这个问题。
最后我通过重新安装 pip
解决了这个问题。
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python3 get-pip.py
相关讨论:
如果你按照以上方法仍没能解决,可查看以下相关讨论从中寻找其他可能的解决方案
https://stackoverflow.com/questions/47955397/pip3-error-namespacepath-object-has-no-attribute-sort
这篇关于Python AttributeError: '_NamespacePath' object has no attribute 'sort'的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!