Pip: ImportError: cannot import name 'main'

Created on 24 May 2019  路  7Comments  路  Source: pypa/pip

  • Pip version:19.1.1
  • Python version: 3.5
  • Operating system: Raspberry Pi 3B+

I've had issue's with updating Cryptography, and in the faq, I read that it could be because I'm having an old version of pip. So I've updated pip using the next command.
pip install -U pip
After that, i wanted to use pip again and I'm getting the next error:

raceback (most recent call last): File "/usr/bin/pip3", line 9, in from pip import main ImportError: cannot import name 'main'

And now pip doesn't work anymore..

auto-locked support

Most helpful comment

It depends on where you got pip from originally. That's the way to upgrade pip if it's "your" copy of pip (you installed it yourself, via get-pip.py for example, or as part of creating a virtual environment). But if pip was supplied as part of an OS package, then you need to upgrade it according to the rules of that package manager, otherwise you've in effect changed files controlled by your package manager without its knowledge, and things can break.

The docs could be clearer on this matter - although I'm not sure myself how we do so while keeping things clear and focused on pip (we don't want to get into trying to explain all of the various package management systems out there and their quirks...) PRs to improve the docs would be welcome :-)

Now I wanted to upgrade pip.

In your case, if your package vendor hasn't produced a package for the latest version of pip, then you should prompt them to do so, or use a means of having your own copy of pip, for example using a virtualenv. Sorry I can't offer more suggestions here, I don't use Linux myself, so my knowledge is limited.

All 7 comments

See #5599 - basically you should not be using pip install -U pip to upgrade your system pip, as your system pip is managed by your system package manager, and not by pip itself.

Specifically, pip install -U doesn't upgrade the /usr/bin/pip3 script, as that's not something that pip installs, it's handled by your OS package manager, and now it's out of sync with your installed pip package.

There are a number of suggestions/approaches to diagnosing and fixing your precise issue in #5599 - hopefully one of those should fix your issu.

Thanks for the quick response! Pip is working just fine now on version 9.0.1. Now I wanted to upgrade pip. I've checked the upgrading section on the site, but you said that that's not the way how you upgrade pip? So how do I upgrade pip?

It depends on where you got pip from originally. That's the way to upgrade pip if it's "your" copy of pip (you installed it yourself, via get-pip.py for example, or as part of creating a virtual environment). But if pip was supplied as part of an OS package, then you need to upgrade it according to the rules of that package manager, otherwise you've in effect changed files controlled by your package manager without its knowledge, and things can break.

The docs could be clearer on this matter - although I'm not sure myself how we do so while keeping things clear and focused on pip (we don't want to get into trying to explain all of the various package management systems out there and their quirks...) PRs to improve the docs would be welcome :-)

Now I wanted to upgrade pip.

In your case, if your package vendor hasn't produced a package for the latest version of pip, then you should prompt them to do so, or use a means of having your own copy of pip, for example using a virtualenv. Sorry I can't offer more suggestions here, I don't use Linux myself, so my knowledge is limited.

I'm using it on my Raspberry Pi, I think pip was already installed the first time I started the Pi. Thanks for the help

Hi @PlanB007, is everything working for you?

Hi @chrahunt pip works again on my Pi, only on the same version I started (19.1.1). I wasn't able to upgrade it to a higher version.

19.1.1 is the latest, so that should be okay. :+1: Please let us know if you have any other issues.

Was this page helpful?
0 / 5 - 0 ratings