在使用ubuntu16.04+python3.5 下使用pip3出现pip3 error - '_NamespacePath' object has no attribute '

Posted 每天坚持一点点

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在使用ubuntu16.04+python3.5 下使用pip3出现pip3 error - '_NamespacePath' object has no attribute '相关的知识,希望对你有一定的参考价值。

使用pip3安装tensorflow以及gensim等时,出现如下错误:

Traceback (most recent call last):
  File "/usr/local/bin/pip3", line 7, in <module>
    from pip import main
  File "/usr/local/lib/python3.5/dist-packages/pip/__init__.py", line 43, in <module>
    from pip.utils import get_installed_distributions, get_prog
  File "/usr/local/lib/python3.5/dist-packages/pip/utils/__init__.py", line 27, in <module>
    from pip._vendor import pkg_resources
  File "/usr/local/lib/python3.5/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 3018, in <module>
    @_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\'

 然后我试了很多种方法,而且还根据许多其他答案pip3 install --upgrade pip setuptools等等都不行,最终还是在外文的一个讨论区找到一个,修改了一下,觉得还可以:

具体来说就是编辑文件#2121~2122 : "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]

 这样问题就解决啦。打开文件左下角有行号方便查找(如果初次使用vim编辑器,而且希望多会一些vim编辑器,以及对其进行设置,永远显示行号可以看我的另一篇里面有写http://www.cnblogs.com/gaofighting/p/8527421.html)

 

以上是关于在使用ubuntu16.04+python3.5 下使用pip3出现pip3 error - '_NamespacePath' object has no attribute '的主要内容,如果未能解决你的问题,请参考以下文章

Ubuntu16.04 python2.7升级python3.5

在Ubuntu_meta 16.04中设置默认Python3.5的命令

基于ubuntu16.04配置opencv3.1+python3.5

在使用ubuntu16.04+python3.5 下使用pip3出现pip3 error - '_NamespacePath' object has no attribute '

ubuntu 16.04 安装 python3.6

Ubuntu16.04下搭建python3.5+PyQt5.7+Eric6开发环境