}

Python: pip is broken. _internal module cannot be imported

Created:

The error

When you execute:

pip

You get the error:

Traceback (most recent call last):
  File "/usr/local/bin/pip", line7, in <module>
      from pip._internal import main
ImportError: No module named _internal

Another error you could see:

Traceback (most recent call last):
  File "/home/kleinernull/.pyenv/versions/3.6.2/bin/pip", line 7, in <module>
    from pip import main
ImportError: cannot import name 'main'
Traceback (most recent call last):
  File "/home/kleinernull/.pyenv/versions/3.6.2/bin/pip", line 7, in <module>
    from pip import main
ImportError: cannot import name 'main'

Solution: change pip import

pip 10 main function is located in the _internal module, you can edit pip (usually located at /usr/local/bin/pip)

You will see from pip import main, change that line with from pip._internal import main

Solution 2: remove package python-pip

If you are using Ubuntu/Debian you can remove the package python-pip:

sudo apt remove python-pip

Solution 3: Install old pip and upgrade later

You can install pip 9.0.1 and then upgrade pip using pip:

sudo python -m pip install -U pip == 9.0.1
sudo pip install -U pip

Solutio 4: Install pip with get-pip.py

You can download and install pip with curl:

curl https://bootstrap.pypa.io/get-pip.py | python3