pip3错误-'_NamespacePath'对象没有属性'sort' [英] pip3 error - '_NamespacePath' object has no attribute 'sort'

查看:104
本文介绍了pip3错误-'_NamespacePath'对象没有属性'sort'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试通过pip3安装软件包,但出现此错误.我运行的每个pip/pip3命令都会给我这个错误-

I tried to install a package through pip3, and I got this error. Every pip/pip3 command that I run gives me this error-

alexg@hitbox:~$ pip3 -V
Traceback (most recent call last):
  File "/usr/local/bin/pip3", line 7, in <module>
    from pip import main
  File "/home/alexg/.local/lib/python3.5/site-packages/pip/__init__.py", line 26, in <module>
    from pip.utils import get_installed_distributions, get_prog
  File "/home/alexg/.local/lib/python3.5/site-packages/pip/utils/__init__.py", line 27, in <module>
    from pip._vendor import pkg_resources
  File "/home/alexg/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3018, in <module>
    @_call_aside
  File "/home/alexg/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3004, in _call_aside
    f(*args, **kwargs)
  File "/home/alexg/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3046, in _initialize_master_working_set
    dist.activate(replace=False)
  File "/home/alexg/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2578, in activate
    declare_namespace(pkg)
  File "/home/alexg/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2152, in declare_namespace
    _handle_ns(packageName, path_item)
  File "/home/alexg/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2092, in _handle_ns
    _rebuild_mod_path(path, packageName, module)
  File "/home/alexg/.local/lib/python3.5/site-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'

我已经尝试根据一些答案运行pip3 install --upgrade pip setuptools,但是每个pip命令都会给我错误.我被困住了,什么也做不了.

I have tried running pip3 install --upgrade pip setuptools according to some answers, but every pip command gives me the error. I'm stuck and can't do anything.

可能是什么原因引起的,如何解决?

What could have caused it, and how can this be fixed?

我在使用Python 3.5.2

I'm on Ubuntu 16.04 with Python 3.5.2

推荐答案

我在python 3.5.2和pip3(9.0.1)中遇到了相同的问题.然后按照以下变通办法解决了它: https://github.com/pypa/setuptools/issues/885#issuecomment-307696027

I met the same issue with python 3.5.2 and pip3 (9.0.1). And I fixed it by following this workaround: https://github.com/pypa/setuptools/issues/885#issuecomment-307696027

更具体地说,我编辑了该文件的#2121〜2122行:"sudo vim/usr/local/lib/python3.5/dist-packages/pip/_vendor/pkg_resources/__ init __.py"

More specifically, I edited line #2121~2122 of this file: "sudo vim /usr/local/lib/python3.5/dist-packages/pip/_vendor/pkg_resources/__init__.py"

#orig_path.sort(key=position_in_sys_path)
#module.__path__[:] = [_normalize_cached(p) for p in orig_path]
orig_path_t = list(orig_path)
orig_path_t.sort(key=position_in_sys_path)
module.__path__[:] = [_normalize_cached(p) for p in orig_path_t]

这篇关于pip3错误-'_NamespacePath'对象没有属性'sort'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆