pip3 error - '_NamespacePath' object has n

2019-01-21 19:05发布

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'

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?

I'm on Ubuntu 16.04 with Python 3.5.2

9条回答
We Are One
2楼-- · 2019-01-21 19:27

This may sound weird, because I had this issue and I had tried everything mentioned in SO and GitHub issues. But then I installed pip with easyinstall and pip command is working. Maybe now there are 2 pip packages now. But error is gone.

easy_install pip

查看更多
姐就是有狂的资本
3楼-- · 2019-01-21 19:31

Try : sudo easy_install pip and then

sudo easy_install setuptools

It probably happends because of messed-up dependencies.

查看更多
Bombasti
4楼-- · 2019-01-21 19:31

I had this same problem, and was unable to run any command with pip3 (including any commands like pip3 install --upgrade pip setuptools).

Only fix I've found was to completely uninstall and re-install python 3 (sudo apt-get remove python3, sudo apt-get install python3, sudo apt install python3-pip) and now pip3 is working properly again.

查看更多
该账号已被封号
5楼-- · 2019-01-21 19:36

I had the same problem using poetry.

Running

poetry run pip install --upgrade pip setuptools

instead of

pip install --upgrade pip setuptools

fixed the issue.

查看更多
Luminary・发光体
6楼-- · 2019-01-21 19:38

This probably means that your dependencies got messed up.

Try to uninstall pip3 from scratch and it should work.

In case it doesn't work, delete your pip installation. In your case:

rm -r /home/alexg/.local/lib/python3.5/site-packages/pip/

And to be sure next time, best to work with virtual environments :)

查看更多
ゆ 、 Hurt°
7楼-- · 2019-01-21 19:40

I'm using virtualenv and upgrading setuptools didn't work for me. What did work was this workaround:

pip uninstall setuptools -y && pip install setuptools
查看更多
登录 后发表回答