pip3 install not working - No module named 'pip._vendor.pkg_resources'
This solved it for me:
curl -sS https://bootstrap.pypa.io/get-pip.py | sudo python3
try use virtualenv for every specific project not messing with ubuntu subsystem.
Thanks @s_s.411
I solve this problem with the following commands:
curl -sS https://bootstrap.pypa.io/get-pip.py | sudo python3type pip3hash -rpip3
I ran into the same problem, on Ubuntu 16.04, using the system python 3.5.2 like you, with pip installed via apt (sudo apt install python3-pip
) like you, having installed some packages in my home directory with pip3 install --user
like you (documented in your chat with hoefling).
The solution was as follows:
- Temporarily move away all packages installed with
pip3 install --user
:
mv ~/.local/lib/python3.5/site-packages{,_backup}
This made pip3
work again, but of course I wanted to keep the packages. (Note: just moving out setuptools
was not enough; I am not sure which constellation of packages caused this.)
- Install an upgraded pip into home directory:
pip3 install --upgrade --user pip
Now the pip3
command fails (ImportError: cannot import name 'main'
) because it's still called from the old /usr/bin/pip3
location in the current shell, as indicated by type pip3
. To solve this, run:
hash -r
Alternatively, you can always fall back to typing python3 -m pip
instead of pip3
.
- Restore the packages:
mv ~/.local/lib/python3.5/site-packages{_backup/*,}rmdir ~/.local/lib/python3.5/site-packages_backup
- Now pip was working, but
python3 -m 'import setuptools'
failed with the same exception you saw,AttributeError: '_NamespacePath' object has no attribute 'sort'
. This could be solved by uninstalling, then reinstalling thesetuptools
package in my home directory (uninstalling alone was not enough):
pip3 uninstall setuptoolspip3 install --user --upgrade setuptools
Finally, pip3
and the python3 -c 'import setuptools'
are fine.