How to reinstall system python 2.7 on Linux Mint 18.3 WITHOUT reinstalling the OS?











up vote
1
down vote

favorite
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?










share|improve this question






















  • This is one of my annoyances with the new pip 10 release. The packages you are using expect pip <= 9.
    – Edward Minnix
    Jun 11 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.
    – James Draper
    Jun 11 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).
    – Edward Minnix
    Jun 11 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 at 21:43















up vote
1
down vote

favorite
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?










share|improve this question






















  • This is one of my annoyances with the new pip 10 release. The packages you are using expect pip <= 9.
    – Edward Minnix
    Jun 11 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.
    – James Draper
    Jun 11 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).
    – Edward Minnix
    Jun 11 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 at 21:43













up vote
1
down vote

favorite
1









up vote
1
down vote

favorite
1






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?










share|improve this question













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?







linux-mint apt python pip






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jun 11 at 17:21









James Draper

15818




15818












  • This is one of my annoyances with the new pip 10 release. The packages you are using expect pip <= 9.
    – Edward Minnix
    Jun 11 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.
    – James Draper
    Jun 11 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).
    – Edward Minnix
    Jun 11 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 at 21:43


















  • This is one of my annoyances with the new pip 10 release. The packages you are using expect pip <= 9.
    – Edward Minnix
    Jun 11 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.
    – James Draper
    Jun 11 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).
    – Edward Minnix
    Jun 11 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 at 21:43
















This is one of my annoyances with the new pip 10 release. The packages you are using expect pip <= 9.
– Edward Minnix
Jun 11 at 19:42




This is one of my annoyances with the new pip 10 release. The packages you are using expect pip <= 9.
– Edward Minnix
Jun 11 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.
– James Draper
Jun 11 at 19:48




@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.
– James Draper
Jun 11 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).
– Edward Minnix
Jun 11 at 20:00




This is not a Python 2 versus Python 3 issue, this is a pip issue (anything from 2.7 to 3.6).
– Edward Minnix
Jun 11 at 20:00




1




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 at 21:43




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 at 21:43










2 Answers
2






active

oldest

votes

















up vote
1
down vote













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





share|improve this answer





















  • on my broken python this Successfully installed pip-8.1.1
    – U.V.
    Nov 23 at 13:54


















up vote
1
down vote













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






share|improve this answer





















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "106"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f449167%2fhow-to-reinstall-system-python-2-7-on-linux-mint-18-3-without-reinstalling-the-o%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    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





    share|improve this answer





















    • on my broken python this Successfully installed pip-8.1.1
      – U.V.
      Nov 23 at 13:54















    up vote
    1
    down vote













    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





    share|improve this answer





















    • on my broken python this Successfully installed pip-8.1.1
      – U.V.
      Nov 23 at 13:54













    up vote
    1
    down vote










    up vote
    1
    down vote









    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





    share|improve this answer












    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






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jun 11 at 19:47









    Edward Minnix

    1114




    1114












    • on my broken python this Successfully installed pip-8.1.1
      – U.V.
      Nov 23 at 13:54


















    • on my broken python this Successfully installed pip-8.1.1
      – U.V.
      Nov 23 at 13:54
















    on my broken python this Successfully installed pip-8.1.1
    – U.V.
    Nov 23 at 13:54




    on my broken python this Successfully installed pip-8.1.1
    – U.V.
    Nov 23 at 13:54












    up vote
    1
    down vote













    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






    share|improve this answer

























      up vote
      1
      down vote













      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






      share|improve this answer























        up vote
        1
        down vote










        up vote
        1
        down vote









        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






        share|improve this answer












        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







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 at 16:08









        U.V.

        614




        614






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f449167%2fhow-to-reinstall-system-python-2-7-on-linux-mint-18-3-without-reinstalling-the-o%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            サソリ

            広島県道265号伴広島線

            Accessing regular linux commands in Huawei's Dopra Linux