3

My pip broke after I ran

pip install --upgrade pip

When I run this command

pip -V

or any other commands I get

Traceback (most recent call last):
  File "/usr/bin/pip", line 9, in <module>
    from pip import main
ImportError: cannot import name main

Why is it breaking? I have python3 installed. I have a solution but I need to understand why it broke after upgrading to the latest version.

  • 2
    can you try using pip3 instead of pip.. i see a similar error [here](https://stackoverflow.com/questions/43675074/python3-6-importerror-cannot-import-name-main-linux-rhel6) – segFaulter Jun 04 '18 at 11:57
  • i will try that, thank but i have not got the explanation why it brakes right yet. – Ayejuni Ilemobayo Kings Jun 04 '18 at 12:03
  • It also happened on my virtual machine, when I was just experimenting with different Linux distros, I didn't want to search for the root cause of this problem, but I am fav'ing to follow answers. – BcK Jun 04 '18 at 12:03
  • i solved it with this `python -m pip uninstall pip` but still suggested i update pip – Ayejuni Ilemobayo Kings Jun 04 '18 at 12:05
  • The Python3 formula does not override pip in HOMEBREW_PREFIX/bin. The part that overrides pip is when a user manually runs a pip3 install --upgrade pip and that logic is handled by pip itself rather than Homebrew or the Python3 formula. – Nishant Patel Jun 04 '18 at 13:09

1 Answers1

1

pip authors were warning for many years to not import pip. Finally at version 10 they restructured their code.

Your /usr/bin/pip was not upgraded (probably because pip install -U pip installed new /usr/local/bin/pip) so it uses the old API before renaming.

If that's the case I recommend to put /usr/local/bin before /usr/bin in $PATH.

phd
  • 82,685
  • 13
  • 120
  • 165