163

Running pip or pip3 results with:

Traceback (most recent call last):
File "/home/myuser/.local/bin/pip", line 7, in <module>
from pip._internal import main
ImportError: No module named 'pip._internal'

I had issues with this, and uninstalled pip3, but when i try to install it again using

sudo apt-get -y install python3-pip

it does install, but then running pip or pip3 i get the same error.

#which pip3
/home/myuser/.local/bin/pip3
Yaron
  • 13,453
Keweik
  • 1,731

8 Answers8

252

After upgrading pip (or pip3, in this case) if the following occurs:

$ ~ pip3 -V
Traceback (most recent call last):
  File "/usr/local/bin/pip", line 7, in <module>
    from pip._internal import main
ModuleNotFoundError: No module named 'pip._internal'

Force a reinstall of pip:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py --force-reinstall

Verify install:

$ ~ pip3 -V
pip 10.0.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)

Now pip3 install <package> and pip3 install --user <package> (for user-level installs) will work correctly.

There should never, ever be any reason you need to run pip in elevated mode.

For Python 2.7

curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py
python get-pip.py --force-reinstall

Had same problem on macOS as well, it's a common issue across platforms.

Benjamin R
  • 2,952
60

I solved this by updating pip via Python, like this:

python2 -m pip install --user --upgrade pip
python3 -m pip install --user --upgrade pip
Kevin Bowen
  • 20,055
  • 57
  • 82
  • 84
cdutra
  • 1,179
27

This command also works. It reinstalls pip:

sudo easy_install pip
cdutra
  • 1,179
9

Apply these three steps:

  1. Go to /usr/local/bin by terminal
  2. Execute sudo gedit pip
  3. Change the from pip._internal import main into from pip import main.
zx485
  • 2,865
7

Check if pip is already installed using

pip3 -V 

or

pip3 --version

If not use this command to install it:

sudo apt install python3-pip

Now you can use

python3 -m pip install packageName

to install packages using pip.

Zanna
  • 72,312
3

I got the same problem as you just now, I found the reason is that you are working without superuser privilege since some internal python packages or modules are installed under superuser privilege.

So you can try by fist entering sudo su, then enter your password, and run pip install, it might help.

Daniel
  • 141
2

A force re-install of pip with -H flag worked for me:

sudo -H python3.7 get-pip.py --force-reinstall
Eliah Kagan
  • 119,640
zoozoo
  • 151
1

The pip version now is 19.0.1:

which pip3
#/home/xxx/.local/bin/pip3
vim /home/xxx/.local/bin/pip3

Change from pip._internal import main into from pip import main

Alan Lau
  • 11
  • 1