1

On a clean install of Linux Mint 18.3 I ran the following commands through the terminal:

sudo apt install python-pip
pip install install --upgrade pip
pip install future
pip install six

Now when I run pip install <package name> or sudo pip install <package name> neither works. Generally I'll get an error message that looks like this:

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

I think it was the pip install install --upgrade pip command that broke everything but yeah this was a terrible idea and I've given up on what I was trying to. All I want now it to return my system python to it's factory setting without having to completely reinstall Linux Mint. Is that possible?

4
  • This is one of my annoyances with the new pip 10 release. The packages you are using expect pip <= 9. Jun 11 '18 at 19:42
  • @EdwardMinnix yes it sucks. The python devs seem like they are aggressively trying to kill python 2.7. it's a just cause but sometimes I disagree with their methods. Jun 11 '18 at 19:48
  • This is not a Python 2 versus Python 3 issue, this is a pip issue (anything from 2.7 to 3.6). Jun 11 '18 at 20:00
  • 1
    In fact, it's an Ubuntu issue, because packages installed with apt are protected against overwriting. So when you issue sudo pip install --upgrade pip, you actually don't update anything - you install another copy of pip in /usr/local/. The error is because /usr/local/lib/pythonX.X/site-packages precedes /usr/lib/pythonX.X/dist-packages, so pip==8.1.2 from python-pip tries to use incompatible code from pip==10.0.0, thus causing the import error. An easy fix is to place /usr/local/bin before /usr/bin, so the correct executable is used when calling pip.
    – hoefling
    Jun 11 '18 at 21:43
1

If you're issue is being on too-modern a version of pip (10+), you can always revert it to the previous version (e.g., pip 9.0.3 which was the last version prior to pip 10). You can do this from the command line:

pip install pip==9.0.3
1
  • on my broken python this Successfully installed pip-8.1.1
    – U.V.
    Nov 23 '18 at 13:54
1

I am on a virtualbox linuxmint 18 Sarah installation. I got into a real mess when I tried to update pip. (eventually a missing frozen keyword when using the new pip for installations)

After trying to follow the various instructions like the one above, I did a brute force reinstall until I could run my python tests again and continue development.

Here it goes:

  • First the system upgrade (apt update && apt upgrade)
  • then remove all python installations brute force
    (uninstalling python2.7 with the package manager will leave many broken packages behind)

    rm -f /usr/bin/pip*
    rm -rf /usr/lib/python2.7
    
    rm -f /usr/local/bin/pip*
    rm -f /usr/local/bin/pyt*
    rm -f /usr/local/bin/pip*
    rm -rf /usr/local/lib/python2.7
    
    rm -rf $HOME/.local/bin/pyt*
    rm -rf $HOME/.local/bin/pip*
    rm -rf $HOME/.local/lib/python2.7
    
  • reinstall python from linux packages giving a working pip

    apt install python2.7  --reinstall
    apt install python-pip --reinstall
    apt install python-setuptools --reinstall
    apt install python-pkg-resources  --reinstall
    
  • reinstall needed python package from using pip, e.g.:

    pip install wheel
    pip install grequests        
    pip install pytest
    pip install flask
    pip install chardet
    pip install prometheus_client
    pip install bs4
    

The python packages you need to reinstall might vary obviously for your setup. I hope I didn't miss anything important from my command history, but you should get the general idea. The longest was the system upgrade. Everything else wen quite quick

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.