pip: pip ImportError: cannot import name 'main' after update

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


Environment

  • pip version: ???
  • Python version: 3.5.2
  • OS: Linux sas-linuxmint 4.4.0-92-generic #115-Ubuntu SMP Thu Aug 10 09:04:33 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
sas@sas-linuxmint /usr/bin $ pip3 install --user --upgrade pip
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
Successfully installed pip-8.1.1
You are using pip version 8.1.1, however version 10.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
ImportError: cannot import name 'main'
sas@sas-linuxmint /usr/bin $ pip3 install --upgrade pip
Traceback (most recent call last):
  File "/usr/bin/pip3", line 9, in <module>
    from pip import main
ImportError: cannot import name 'main'

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 5
  • Comments: 18 (5 by maintainers)

Most upvoted comments

hash -d pip worked for me

I had the same problem, but uninstall and reinstall with apt and pip didn’t work for me.

I saw another solution on stackoverflow that presents a easy way to recover pip3 path:

sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall

@pradyunsg Why are you marking this a duplicate of a closed issue? It’s clearly not closed if it’s still an issue…

Use pip3 👍

In this case, the particular issue seems to be:

  1. pip3 install --user --upgrade pip installs pip 10 in the user site, but doesn’t uninstall the system site copy of pip.
  2. User runs the system wrapper from /usr/bin/pip3 which is from the OS-supplied pip 8. This wrapper expects to see pip 8, but it doesn’t because user site takes priority over system site.

The solution is to use the pip wrapper installed when you installed pip 10 in --user. That will mean changing your PATH to put that first, or using an explicit path when you invoke pip.

Technically the issue here is slightly different from #5221, as in that issue users were overwriting the system pip. But the root cause is the same - using an older pip wrapper (supplied by the OS) against a newer version of pip. That’s not a supported scenario, and you can’t encounter it with correct use of pip. So there’s no pip issue, hence we close the issues when they arise. We’re directing users at #5221 because that’s where the bulk of the advice on how to tidy up your system after an incorrect upgrade is located.

@linpanusst is correct

sudo ln -sf $( type -P pip ) /usr/bin/pip

you should try using python3 -m pip install --user “packagename”

This is the same as #5221.