1

I've installed the latest Ubuntu Gnome today, and was setting-up my machine for data science-related work. When I tried installing tensorflow-gpu, I ran into a crash from pip3:

me@pc:~/Desktop$ 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'

I tried purging python3-pip and reinstalling, still does not work. I get the above just by running pip3 in the terminal and hitting ENTER.

Any ideas?

EDIT: Also the two paths are different for pip and pip3:

me@pc:~$ which pip
/home/me/.local/bin/pip
me@pc:~$ which pip3
/usr/bin/pip3
0

I fixed this by creating a new virtual environment

  1. A new virtual environment can be created by:

    python3 -m venv /tmp/newvenv
    
  2. Then I checked if pip works ok in the new virtual environment:

    cd /tmp/newvenv/bin
    ./pip3
    

This gave me the normal message as in the following:

Usage:
pip [options]

Commands:

install Install packages.

download Download packages.

...

However, pip3 still has failed.

    pip3

This still gave me the error message.

Then I decided to copy working versions of pip to the home directory. For the below two steps (#3 and #4) you may want to keep backup copies.

  1. I have overwritten pip and pip-9.0.1.dist-info from the virtual environment to home directory:

    cp -r /tmp/newvenv/lib/python3.5/site-packages/pip ~/.local/lib/python3.5/site-packages/
    cp -r /tmp/newvenv/lib/python3.5/site-packages/pip-9.0.1.dist-info ~/.local/lib/python3.5/site-packages/
    
  2. I also copied the following two files:

    cp /tmp/newvenv/lib/python3.5/site-packages/pkg_resources/__init__.py ~/.local/lib/python3.5/site-packages/pkg_resources/ 
    cp /tmp/newvenv/lib/python3.5/site-packages/pkg_resources/py31compat.py ~/.local/lib/python3.5/site-packages/pkg_resources/
    

After these steps pip3 is working ok in my case.

| improve this answer | |
-1

Your python setuptools package is broken.

Run sudo apt install python3-setuptools first.

then,

pip3 install --upgrade setuptools
pip3 install --upgrade pip
| improve this answer | |
  • 2
    first, I need pip3, not pip. Second, I cannot use pip3 for anything. Simply executing pip3 gives the above error. – Qubix Jan 22 '18 at 8:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.