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 l
from pip._internal import main
Edit the pip code from
sudo nano /usr/bin/pip3
Use the following command before the execution of any pip command
hash -d pip
It will work
What worked for me to fix the error with using pip3
was:
sudo cp -v /usr/local/bin/pip3 /usr/bin/pip3
Everything works:
demon@UbuntuHP:~$ pip -V
pip 10.0.1 from /usr/local/lib/python3.5/dist-packages/pip (python 3.5)
demon@UbuntuHP:~$ pip2 -V
pip 10.0.1 from /home/demon/.local/lib/python2.7/site-packages/pip (python 2.7)
demon@UbuntuHP:~$ pip3 -V
pip 10.0.1 from /usr/local/lib/python3.5/dist-packages/pip (python 3.5)
Maybe the new 10.0.1 version of pip doesn't update the binary in /usr/bin ? (which seems it does not)
EDIT: the same issue occurs in Ubuntu 18.04. The best solution I've found is to symlink the pip binaries from /home/<user/.local/bin
to /usr/local/bin
or /usr/bin
(depending on your preference), as follows:
ln -sv /home/<user>/.local/bin/pip /usr/local/bin/pip
ln -sv /home/<user>/.local/bin/pip2 /usr/local/bin/pip2
ln -sv /home/<user>/.local/bin/pip2.7 /usr/local/bin/pip2.7
ln -sv /home/<user>/.local/bin/pip3 /usr/local/bin/pip3
ln -sv /home/<user>/.local/bin/pip3.6 /usr/local/bin/pip3.6
NOTE: replace <user>
with your current running user
The associated versions (latest) are in:
/home/demon/.local/lib/python3.6/site-packages/pip (python 3.6)
/home/demon/.local/lib/python2.7/site-packages/pip (python 2.7)
Is something wrong with the packages, when it generating de file /usr/bin/pip, you have to change the import:
from pip import main
to
from pip._internal import main
That solves the problem, I'm not sure why it generated, but it saids somthing in the following issue:
After pip 10 upgrade on pyenv "ImportError: cannot import name 'main'"
On Debian you will need to update apt first....
sudo apt-get update -qq
sudo apt-get install python-pip -qq
sudo pip install pip --upgrade --quiet
sudo pip2 install virtualenv --quiet
If you skip 'sudo apt-get update -qq' your pip will become corrupt and display the 'cannot find main' error.
This error may be a permission one. So, test executing the command with -H flag:
sudo -H pip3 install numpy