Whenever I am trying to install any package using pip, I am getting this import error:
guru@guru-notebook:~$ pip3 install numpy
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import main
ImportError: cannot import name 'main'
guru@guru-notebook:~$ cat `which pip3`
#!/usr/bin/python3
# GENERATED BY DEBIAN
import sys
# Run the main entry point, similarly to how setuptools does it, but because
# we didn't install the actual entry point from setup.py, don't use the
# pkg_resources API.
from pip import main
if __name__ == '__main__':
sys.exit(main())
It was working fine earlier, I am not sure why it is throwing this error. I have searched about this error, but can't find anything to fix it.
Please let me know if you need any further detail, I will update my question.
Use
python -m pip install
instead ofpip install
The
pip
(resp.pip3
) executable is provided by your distro (python-pip
package on Ubuntu 16.04) and located at/usr/bin/pip
.Therefore, it is not kept up-to date with the
pip
package itself as you upgrade pip, and may break.If you just use
python -m pip
directly, e.g. as in:it goes through your Python path and finds the latest version of pip, and executes that file.
It relies on the fact that that file is executable through
import
, but that is a very standard type of interface, and therefore less likely to break than the hackier Debian script.Then I recommend adding the following aliases to your
.bashrc
:Tested in Ubuntu 16.04 after an update from
pip3
9.0.1 to 18.0.fellows! I have the same problem and solved it. Here is my solution. First, when I run pip install something, the error came out like this:
So, I cd into the file /usr/bin/ and cat pip3 to see the code in it. I see this in it:
And then I think that it was not in the installation path. So I cd into the python3-pip, like this:
ps: you have to cd into the right directions in your computer Then I cat the file to see the differences(you can use other operations to see the code):
And I saw this:
So, can you see the difference? I can figure out that I have to make the file the same as the file in /usr/bin/pip3
So, I copped the code in /.local/lib/python3.5/site-packages/pip to replace the code in /usr/bin/pip3 and the problem disappear!
ps: pip3 or pip have no difference in this problem. I will be happy if my solution solve your problem!
I use
sudo apt remove python3-pip
thenpip
works.I met the same problem on my Ubuntu 16.04 system. I managed to fix it by re-installing pip with the following command:
curl https://bootstrap.pypa.io/get-pip.py | sudo python3
What worked for me to fix the error with using
pip3
was:sudo cp -v /usr/local/bin/pip3 /usr/bin/pip3
Everything works:
Maybe the new 10.0.1 version of pip doesn't update the binary in /usr/bin ?
Trick and works too