pip: ModuleNotFoundError: No module named 'pip._internal'

Maintainer note: Anyone that still gets this issue please see #5599.


  • Pip version: 10.0.1
  • Python version: 3.6.5-2
  • Operating system: 4.16.3-1-ARCH

Description:

sudo pip install --upgrade pip using 9.0.1-3.

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

What (other) I’ve run:

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

# Back to 9.0.1-3
pacman -Sy --force python-pip
pip uninstall pip
python3 get-pip.py

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 21
  • Comments: 28 (7 by maintainers)

Commits related to this issue

Most upvoted comments

I hit the same snag and just reinstalled pip:

sudo easy_install pip

This worked for me: python3 -m pip install --user --upgrade pip

Maybe the following will work better?

pip3 install --user --upgrade pip

I got the same error from upgrading pip

I removed pip3 files from /usr/local/bin/

and pip folder from /usr/local/lib/python3.5/dist-packages

and uninstalled python3-pip, before reinstalling

and it works again

sudo easy_install3 pip worked for me

Similar to #5221. The installed OS installed pip is doing something weird.

Are the following different?

python3 -m pip --version
pip3 --version

@swprojects Your issue sounds like a distribution specific packaging issue. I request you to open an issue with your Linux Distribution and ask them to look into it.

Thanks!

the pip3 command is distribution managed - pip is completely unaware of it

in general upgrading a distribution managed pip using pip is an act of vandalism and any following breakage is on the vandal who inflicted the issue

  • Pip version: 10.0.1
  • Python version: 3.6.5-2
  • Operating system: 4.16.3-1-ARCH

Description:

sudo pip install --upgrade pip using 9.0.1-3.

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

What (other) I’ve run:

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

# Back to 9.0.1-3
pacman -Sy --force python-pip
pip uninstall pip
python3 get-pip.py

Works for me, Thanks.

@pradyunsg They are equal for the repo version 9.0.1

$ python3 -m pip --version
pip 9.0.1 from /usr/lib/python3.6/site-packages (python 3.6)

$ pip3 --version
pip 9.0.1 from /usr/lib/python3.6/site-packages (python 3.6)

and different for 10.0.1:

$ sudo pip install --upgrade pip
Cache entry deserialization failed, entry ignored
Collecting pip
  Using cached https://files.pythonhosted.org/packages/0f/74/ecd13431bcc456ed390b44c8a6e917c1820365cbebcb6a8974d1cd045ab4/pip-10.0.1-py2.py3-none-any.whl
Installing collected packages: pip
  Found existing installation: pip 9.0.1
    Uninstalling pip-9.0.1:
      Successfully uninstalled pip-9.0.1
Successfully installed pip-10.0.1

$ python3 -m pip --version
/usr/bin/python3: No module named pip.__main__; 'pip' is a package and cannot be directly executed

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

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

Worked for me

@swprojects It will be in the next release of pip. 😃

Thanks for filing this issue.

This worked for me: python3 -m pip install --user --upgrade pip

THANK YOU! My pip broke suddenly for no apparent reason the other week and I’ve tried googling all kinds of error messages and troubleshooting and uninstalling and reinstalling. This is the only thing that’s worked.

sudo apt remove python3-pip worked for me

@jesswren did you try pip3 and not just pip?

Installing python3-pip is for python3, then command is pip3.

Likewise, if python2 then install python-pip, then command is pip.

edit: may not be that, but ubuntu prompts the user to install pip if it is not installed. Not sure if debian does the same thing.

This worked for me: python3 -m pip install --user --upgrade pip

Also works for python2

You shouldn’t be doing sudo pip. https://stackoverflow.com/questions/21055859/what-are-the-risks-of-running-sudo-pip

Looking at this, it seems to be an issue of trying to use pip to modify what your OS package manager has installed (through the use of sudo). It’s likely that is why things are breaking here.