Running Pip3 ImportError: cannot import name 'main'











up vote
8
down vote

favorite
2












I want to install Scipy (already have Numpy installed). I have Python 3.5.1-3 installed with OS and IDLE3 (3.5.2). When I hit in terminal



sudo pip3 install scipy


It prints out



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


I've already tried to reinstall pip3 and restart OS, but it didn't change.
Has pip3 been working weirdly with someone else?










share|improve this question


























    up vote
    8
    down vote

    favorite
    2












    I want to install Scipy (already have Numpy installed). I have Python 3.5.1-3 installed with OS and IDLE3 (3.5.2). When I hit in terminal



    sudo pip3 install scipy


    It prints out



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


    I've already tried to reinstall pip3 and restart OS, but it didn't change.
    Has pip3 been working weirdly with someone else?










    share|improve this question
























      up vote
      8
      down vote

      favorite
      2









      up vote
      8
      down vote

      favorite
      2






      2





      I want to install Scipy (already have Numpy installed). I have Python 3.5.1-3 installed with OS and IDLE3 (3.5.2). When I hit in terminal



      sudo pip3 install scipy


      It prints out



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


      I've already tried to reinstall pip3 and restart OS, but it didn't change.
      Has pip3 been working weirdly with someone else?










      share|improve this question













      I want to install Scipy (already have Numpy installed). I have Python 3.5.1-3 installed with OS and IDLE3 (3.5.2). When I hit in terminal



      sudo pip3 install scipy


      It prints out



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


      I've already tried to reinstall pip3 and restart OS, but it didn't change.
      Has pip3 been working weirdly with someone else?







      python3 pip






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Apr 17 at 11:11









      The Invertible Hog Dog

      43113




      43113






















          7 Answers
          7






          active

          oldest

          votes

















          up vote
          5
          down vote



          accepted










          numpy and scipy are in the default repositories of all currently supported versions of Ubuntu. To install numpy and scipy for Python 3.x open the terminal and type:



          sudo apt update    
          sudo apt install python3-numpy python3-scipy


          For Python 2.x it's:



          sudo apt update  
          sudo apt install --no-install-recommends python2.7-minimal python2.7 # this line is only necessary for Ubuntu 17.10 and later
          sudo apt install python-numpy python-scipy





          share|improve this answer





















          • python3-scipy worked just fine. Thanks!
            – The Invertible Hog Dog
            Apr 17 at 14:04










          • As another answer states, this answer is not related to the underlying issue, which has to do with pip.
            – cjauvin
            Apr 20 at 15:16






          • 1




            Updating pip to the latest version may fix it. Python 2.x: sudo -H pip install --upgrade pip and/or Python 3.x: sudo -H pip3 install --upgrade pip The -H flag tells sudo to keep the home directory of the current user. This way when pip installs things, like pip itself, it uses the appropriate directory.
            – karel
            Apr 20 at 15:23




















          up vote
          5
          down vote













          While karel may have solved your "install numpy and scipy" problem, what's wrong with pip on your system hasn't been addressed, so you'll probably have more problems with pip going forward.



          Looking here, it seems to be a pretty common recent issue with pip 10 on Ubuntu systems. You may find some work arounds on that thread that work for you, but hopefully an update will fix it soon.






          share|improve this answer





















          • Thank you for actually fixing the problem and not giving a work-around that only solves the problem partially and for only a single person...
            – Caleb Fenton
            Aug 15 at 21:44


















          up vote
          4
          down vote













          The bug is found in pip 10.0.0.



          In linux you need to modify file: /usr/bin/pip from:



          from pip import main
          if __name__ == '__main__':
          sys.exit(main())


          to this:



          from pip import __main__
          if __name__ == '__main__':
          sys.exit(__main__._main())





          share|improve this answer























          • This style of workaround does not seem recommended by the pip team.
            – jdk1.0
            Jul 15 at 20:21












          • You saved my day!!
            – Saurabh Singh
            Sep 2 at 17:52


















          up vote
          1
          down vote













          Use python -m pip install instead of pip install



          I started getting this problem after a pip upgrade:



          pip install --upgrade --user pip


          The pip (resp. pip3) executable is provided by your distro (python-pip package on Ubuntu 16.04).



          Therefore, it is not kept up-to date with the pip package itself as you upgrade pip, and may break.



          If you just use python -m pip directly, e.g. as in:



          python -m pip install --user somepackage
          python3 -m pip install --user somepackage


          it goes through your Python path and finds the latest version of pip, and executes that file.



          It relies on the fact that that file is executable, but that is a very standard type of interface, and therefore less likely to break than the hackier Debian script.



          Then I recommend adding the following aliases to your .bashrc:



          pip() ( python -m pip "$@" )
          pip3() ( python3 -m pip "$@" )


          Tested in Ubuntu 16.04 after an update from pip3 9.0.1 to 18.0.






          share|improve this answer




























            up vote
            0
            down vote













            Installing pip from both apt and pip itself can cause this.



            In my case, I used Ubuntu's pip package to install pipenv which then installed a newer copy of pip. Now because my shell runs Ubuntu's pip 9 script (to verify run which pip3) and my Python interpreter then imports the pip 10 module, the pip3 command fails. So I want to uninstall one of the two.



            It's fair to assume you have the newer pip for a reason. In that case you want to uninstall the older pip like so:



            sudo apt remove python3-pip



            If you know for sure that you're fine with the older pip and prefer the system package you'll want to uninstall the newer one:



            ~/.local/bin/pip3 uninstall pip



            or failing that



            sudo /usr/local/bin/pip3 uninstall pip






            share|improve this answer




























              up vote
              0
              down vote













              My issue ended up being a mismatch between python3.6 and 3.7. The python3.6 installation put a link in /usr/bin/python3 -> /usr/bin/python3.6 even though the system had upgraded to python3.7.



              sudo apt purge python-pip
              sudo apt purge python3-pip
              sudo apt install python3.7 --reinstall
              cd /usr/bin
              sudo rm python3
              sudo ln -s python3.7 python3
              python3 --version
              pip3 --version





              share|improve this answer






























                up vote
                -1
                down vote













                This worked for me:



                pip install --upgrade --user pip


                By install --upgrade, I mean whatever you're trying to install.






                share|improve this answer





















                  Your Answer








                  StackExchange.ready(function() {
                  var channelOptions = {
                  tags: "".split(" "),
                  id: "89"
                  };
                  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: true,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: 10,
                  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%2faskubuntu.com%2fquestions%2f1025793%2frunning-pip3-importerror-cannot-import-name-main%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest















                  Required, but never shown

























                  7 Answers
                  7






                  active

                  oldest

                  votes








                  7 Answers
                  7






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes








                  up vote
                  5
                  down vote



                  accepted










                  numpy and scipy are in the default repositories of all currently supported versions of Ubuntu. To install numpy and scipy for Python 3.x open the terminal and type:



                  sudo apt update    
                  sudo apt install python3-numpy python3-scipy


                  For Python 2.x it's:



                  sudo apt update  
                  sudo apt install --no-install-recommends python2.7-minimal python2.7 # this line is only necessary for Ubuntu 17.10 and later
                  sudo apt install python-numpy python-scipy





                  share|improve this answer





















                  • python3-scipy worked just fine. Thanks!
                    – The Invertible Hog Dog
                    Apr 17 at 14:04










                  • As another answer states, this answer is not related to the underlying issue, which has to do with pip.
                    – cjauvin
                    Apr 20 at 15:16






                  • 1




                    Updating pip to the latest version may fix it. Python 2.x: sudo -H pip install --upgrade pip and/or Python 3.x: sudo -H pip3 install --upgrade pip The -H flag tells sudo to keep the home directory of the current user. This way when pip installs things, like pip itself, it uses the appropriate directory.
                    – karel
                    Apr 20 at 15:23

















                  up vote
                  5
                  down vote



                  accepted










                  numpy and scipy are in the default repositories of all currently supported versions of Ubuntu. To install numpy and scipy for Python 3.x open the terminal and type:



                  sudo apt update    
                  sudo apt install python3-numpy python3-scipy


                  For Python 2.x it's:



                  sudo apt update  
                  sudo apt install --no-install-recommends python2.7-minimal python2.7 # this line is only necessary for Ubuntu 17.10 and later
                  sudo apt install python-numpy python-scipy





                  share|improve this answer





















                  • python3-scipy worked just fine. Thanks!
                    – The Invertible Hog Dog
                    Apr 17 at 14:04










                  • As another answer states, this answer is not related to the underlying issue, which has to do with pip.
                    – cjauvin
                    Apr 20 at 15:16






                  • 1




                    Updating pip to the latest version may fix it. Python 2.x: sudo -H pip install --upgrade pip and/or Python 3.x: sudo -H pip3 install --upgrade pip The -H flag tells sudo to keep the home directory of the current user. This way when pip installs things, like pip itself, it uses the appropriate directory.
                    – karel
                    Apr 20 at 15:23















                  up vote
                  5
                  down vote



                  accepted







                  up vote
                  5
                  down vote



                  accepted






                  numpy and scipy are in the default repositories of all currently supported versions of Ubuntu. To install numpy and scipy for Python 3.x open the terminal and type:



                  sudo apt update    
                  sudo apt install python3-numpy python3-scipy


                  For Python 2.x it's:



                  sudo apt update  
                  sudo apt install --no-install-recommends python2.7-minimal python2.7 # this line is only necessary for Ubuntu 17.10 and later
                  sudo apt install python-numpy python-scipy





                  share|improve this answer












                  numpy and scipy are in the default repositories of all currently supported versions of Ubuntu. To install numpy and scipy for Python 3.x open the terminal and type:



                  sudo apt update    
                  sudo apt install python3-numpy python3-scipy


                  For Python 2.x it's:



                  sudo apt update  
                  sudo apt install --no-install-recommends python2.7-minimal python2.7 # this line is only necessary for Ubuntu 17.10 and later
                  sudo apt install python-numpy python-scipy






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Apr 17 at 11:17









                  karel

                  54.6k11119138




                  54.6k11119138












                  • python3-scipy worked just fine. Thanks!
                    – The Invertible Hog Dog
                    Apr 17 at 14:04










                  • As another answer states, this answer is not related to the underlying issue, which has to do with pip.
                    – cjauvin
                    Apr 20 at 15:16






                  • 1




                    Updating pip to the latest version may fix it. Python 2.x: sudo -H pip install --upgrade pip and/or Python 3.x: sudo -H pip3 install --upgrade pip The -H flag tells sudo to keep the home directory of the current user. This way when pip installs things, like pip itself, it uses the appropriate directory.
                    – karel
                    Apr 20 at 15:23




















                  • python3-scipy worked just fine. Thanks!
                    – The Invertible Hog Dog
                    Apr 17 at 14:04










                  • As another answer states, this answer is not related to the underlying issue, which has to do with pip.
                    – cjauvin
                    Apr 20 at 15:16






                  • 1




                    Updating pip to the latest version may fix it. Python 2.x: sudo -H pip install --upgrade pip and/or Python 3.x: sudo -H pip3 install --upgrade pip The -H flag tells sudo to keep the home directory of the current user. This way when pip installs things, like pip itself, it uses the appropriate directory.
                    – karel
                    Apr 20 at 15:23


















                  python3-scipy worked just fine. Thanks!
                  – The Invertible Hog Dog
                  Apr 17 at 14:04




                  python3-scipy worked just fine. Thanks!
                  – The Invertible Hog Dog
                  Apr 17 at 14:04












                  As another answer states, this answer is not related to the underlying issue, which has to do with pip.
                  – cjauvin
                  Apr 20 at 15:16




                  As another answer states, this answer is not related to the underlying issue, which has to do with pip.
                  – cjauvin
                  Apr 20 at 15:16




                  1




                  1




                  Updating pip to the latest version may fix it. Python 2.x: sudo -H pip install --upgrade pip and/or Python 3.x: sudo -H pip3 install --upgrade pip The -H flag tells sudo to keep the home directory of the current user. This way when pip installs things, like pip itself, it uses the appropriate directory.
                  – karel
                  Apr 20 at 15:23






                  Updating pip to the latest version may fix it. Python 2.x: sudo -H pip install --upgrade pip and/or Python 3.x: sudo -H pip3 install --upgrade pip The -H flag tells sudo to keep the home directory of the current user. This way when pip installs things, like pip itself, it uses the appropriate directory.
                  – karel
                  Apr 20 at 15:23














                  up vote
                  5
                  down vote













                  While karel may have solved your "install numpy and scipy" problem, what's wrong with pip on your system hasn't been addressed, so you'll probably have more problems with pip going forward.



                  Looking here, it seems to be a pretty common recent issue with pip 10 on Ubuntu systems. You may find some work arounds on that thread that work for you, but hopefully an update will fix it soon.






                  share|improve this answer





















                  • Thank you for actually fixing the problem and not giving a work-around that only solves the problem partially and for only a single person...
                    – Caleb Fenton
                    Aug 15 at 21:44















                  up vote
                  5
                  down vote













                  While karel may have solved your "install numpy and scipy" problem, what's wrong with pip on your system hasn't been addressed, so you'll probably have more problems with pip going forward.



                  Looking here, it seems to be a pretty common recent issue with pip 10 on Ubuntu systems. You may find some work arounds on that thread that work for you, but hopefully an update will fix it soon.






                  share|improve this answer





















                  • Thank you for actually fixing the problem and not giving a work-around that only solves the problem partially and for only a single person...
                    – Caleb Fenton
                    Aug 15 at 21:44













                  up vote
                  5
                  down vote










                  up vote
                  5
                  down vote









                  While karel may have solved your "install numpy and scipy" problem, what's wrong with pip on your system hasn't been addressed, so you'll probably have more problems with pip going forward.



                  Looking here, it seems to be a pretty common recent issue with pip 10 on Ubuntu systems. You may find some work arounds on that thread that work for you, but hopefully an update will fix it soon.






                  share|improve this answer












                  While karel may have solved your "install numpy and scipy" problem, what's wrong with pip on your system hasn't been addressed, so you'll probably have more problems with pip going forward.



                  Looking here, it seems to be a pretty common recent issue with pip 10 on Ubuntu systems. You may find some work arounds on that thread that work for you, but hopefully an update will fix it soon.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Apr 18 at 8:04









                  JMAA

                  1664




                  1664












                  • Thank you for actually fixing the problem and not giving a work-around that only solves the problem partially and for only a single person...
                    – Caleb Fenton
                    Aug 15 at 21:44


















                  • Thank you for actually fixing the problem and not giving a work-around that only solves the problem partially and for only a single person...
                    – Caleb Fenton
                    Aug 15 at 21:44
















                  Thank you for actually fixing the problem and not giving a work-around that only solves the problem partially and for only a single person...
                  – Caleb Fenton
                  Aug 15 at 21:44




                  Thank you for actually fixing the problem and not giving a work-around that only solves the problem partially and for only a single person...
                  – Caleb Fenton
                  Aug 15 at 21:44










                  up vote
                  4
                  down vote













                  The bug is found in pip 10.0.0.



                  In linux you need to modify file: /usr/bin/pip from:



                  from pip import main
                  if __name__ == '__main__':
                  sys.exit(main())


                  to this:



                  from pip import __main__
                  if __name__ == '__main__':
                  sys.exit(__main__._main())





                  share|improve this answer























                  • This style of workaround does not seem recommended by the pip team.
                    – jdk1.0
                    Jul 15 at 20:21












                  • You saved my day!!
                    – Saurabh Singh
                    Sep 2 at 17:52















                  up vote
                  4
                  down vote













                  The bug is found in pip 10.0.0.



                  In linux you need to modify file: /usr/bin/pip from:



                  from pip import main
                  if __name__ == '__main__':
                  sys.exit(main())


                  to this:



                  from pip import __main__
                  if __name__ == '__main__':
                  sys.exit(__main__._main())





                  share|improve this answer























                  • This style of workaround does not seem recommended by the pip team.
                    – jdk1.0
                    Jul 15 at 20:21












                  • You saved my day!!
                    – Saurabh Singh
                    Sep 2 at 17:52













                  up vote
                  4
                  down vote










                  up vote
                  4
                  down vote









                  The bug is found in pip 10.0.0.



                  In linux you need to modify file: /usr/bin/pip from:



                  from pip import main
                  if __name__ == '__main__':
                  sys.exit(main())


                  to this:



                  from pip import __main__
                  if __name__ == '__main__':
                  sys.exit(__main__._main())





                  share|improve this answer














                  The bug is found in pip 10.0.0.



                  In linux you need to modify file: /usr/bin/pip from:



                  from pip import main
                  if __name__ == '__main__':
                  sys.exit(main())


                  to this:



                  from pip import __main__
                  if __name__ == '__main__':
                  sys.exit(__main__._main())






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jun 9 at 21:28









                  Avram

                  1033




                  1033










                  answered May 24 at 3:56









                  Herman

                  411




                  411












                  • This style of workaround does not seem recommended by the pip team.
                    – jdk1.0
                    Jul 15 at 20:21












                  • You saved my day!!
                    – Saurabh Singh
                    Sep 2 at 17:52


















                  • This style of workaround does not seem recommended by the pip team.
                    – jdk1.0
                    Jul 15 at 20:21












                  • You saved my day!!
                    – Saurabh Singh
                    Sep 2 at 17:52
















                  This style of workaround does not seem recommended by the pip team.
                  – jdk1.0
                  Jul 15 at 20:21






                  This style of workaround does not seem recommended by the pip team.
                  – jdk1.0
                  Jul 15 at 20:21














                  You saved my day!!
                  – Saurabh Singh
                  Sep 2 at 17:52




                  You saved my day!!
                  – Saurabh Singh
                  Sep 2 at 17:52










                  up vote
                  1
                  down vote













                  Use python -m pip install instead of pip install



                  I started getting this problem after a pip upgrade:



                  pip install --upgrade --user pip


                  The pip (resp. pip3) executable is provided by your distro (python-pip package on Ubuntu 16.04).



                  Therefore, it is not kept up-to date with the pip package itself as you upgrade pip, and may break.



                  If you just use python -m pip directly, e.g. as in:



                  python -m pip install --user somepackage
                  python3 -m pip install --user somepackage


                  it goes through your Python path and finds the latest version of pip, and executes that file.



                  It relies on the fact that that file is executable, but that is a very standard type of interface, and therefore less likely to break than the hackier Debian script.



                  Then I recommend adding the following aliases to your .bashrc:



                  pip() ( python -m pip "$@" )
                  pip3() ( python3 -m pip "$@" )


                  Tested in Ubuntu 16.04 after an update from pip3 9.0.1 to 18.0.






                  share|improve this answer

























                    up vote
                    1
                    down vote













                    Use python -m pip install instead of pip install



                    I started getting this problem after a pip upgrade:



                    pip install --upgrade --user pip


                    The pip (resp. pip3) executable is provided by your distro (python-pip package on Ubuntu 16.04).



                    Therefore, it is not kept up-to date with the pip package itself as you upgrade pip, and may break.



                    If you just use python -m pip directly, e.g. as in:



                    python -m pip install --user somepackage
                    python3 -m pip install --user somepackage


                    it goes through your Python path and finds the latest version of pip, and executes that file.



                    It relies on the fact that that file is executable, but that is a very standard type of interface, and therefore less likely to break than the hackier Debian script.



                    Then I recommend adding the following aliases to your .bashrc:



                    pip() ( python -m pip "$@" )
                    pip3() ( python3 -m pip "$@" )


                    Tested in Ubuntu 16.04 after an update from pip3 9.0.1 to 18.0.






                    share|improve this answer























                      up vote
                      1
                      down vote










                      up vote
                      1
                      down vote









                      Use python -m pip install instead of pip install



                      I started getting this problem after a pip upgrade:



                      pip install --upgrade --user pip


                      The pip (resp. pip3) executable is provided by your distro (python-pip package on Ubuntu 16.04).



                      Therefore, it is not kept up-to date with the pip package itself as you upgrade pip, and may break.



                      If you just use python -m pip directly, e.g. as in:



                      python -m pip install --user somepackage
                      python3 -m pip install --user somepackage


                      it goes through your Python path and finds the latest version of pip, and executes that file.



                      It relies on the fact that that file is executable, but that is a very standard type of interface, and therefore less likely to break than the hackier Debian script.



                      Then I recommend adding the following aliases to your .bashrc:



                      pip() ( python -m pip "$@" )
                      pip3() ( python3 -m pip "$@" )


                      Tested in Ubuntu 16.04 after an update from pip3 9.0.1 to 18.0.






                      share|improve this answer












                      Use python -m pip install instead of pip install



                      I started getting this problem after a pip upgrade:



                      pip install --upgrade --user pip


                      The pip (resp. pip3) executable is provided by your distro (python-pip package on Ubuntu 16.04).



                      Therefore, it is not kept up-to date with the pip package itself as you upgrade pip, and may break.



                      If you just use python -m pip directly, e.g. as in:



                      python -m pip install --user somepackage
                      python3 -m pip install --user somepackage


                      it goes through your Python path and finds the latest version of pip, and executes that file.



                      It relies on the fact that that file is executable, but that is a very standard type of interface, and therefore less likely to break than the hackier Debian script.



                      Then I recommend adding the following aliases to your .bashrc:



                      pip() ( python -m pip "$@" )
                      pip3() ( python3 -m pip "$@" )


                      Tested in Ubuntu 16.04 after an update from pip3 9.0.1 to 18.0.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Aug 14 at 16:56









                      Ciro Santilli 新疆改造中心 六四事件 法轮功

                      8,75944145




                      8,75944145






















                          up vote
                          0
                          down vote













                          Installing pip from both apt and pip itself can cause this.



                          In my case, I used Ubuntu's pip package to install pipenv which then installed a newer copy of pip. Now because my shell runs Ubuntu's pip 9 script (to verify run which pip3) and my Python interpreter then imports the pip 10 module, the pip3 command fails. So I want to uninstall one of the two.



                          It's fair to assume you have the newer pip for a reason. In that case you want to uninstall the older pip like so:



                          sudo apt remove python3-pip



                          If you know for sure that you're fine with the older pip and prefer the system package you'll want to uninstall the newer one:



                          ~/.local/bin/pip3 uninstall pip



                          or failing that



                          sudo /usr/local/bin/pip3 uninstall pip






                          share|improve this answer

























                            up vote
                            0
                            down vote













                            Installing pip from both apt and pip itself can cause this.



                            In my case, I used Ubuntu's pip package to install pipenv which then installed a newer copy of pip. Now because my shell runs Ubuntu's pip 9 script (to verify run which pip3) and my Python interpreter then imports the pip 10 module, the pip3 command fails. So I want to uninstall one of the two.



                            It's fair to assume you have the newer pip for a reason. In that case you want to uninstall the older pip like so:



                            sudo apt remove python3-pip



                            If you know for sure that you're fine with the older pip and prefer the system package you'll want to uninstall the newer one:



                            ~/.local/bin/pip3 uninstall pip



                            or failing that



                            sudo /usr/local/bin/pip3 uninstall pip






                            share|improve this answer























                              up vote
                              0
                              down vote










                              up vote
                              0
                              down vote









                              Installing pip from both apt and pip itself can cause this.



                              In my case, I used Ubuntu's pip package to install pipenv which then installed a newer copy of pip. Now because my shell runs Ubuntu's pip 9 script (to verify run which pip3) and my Python interpreter then imports the pip 10 module, the pip3 command fails. So I want to uninstall one of the two.



                              It's fair to assume you have the newer pip for a reason. In that case you want to uninstall the older pip like so:



                              sudo apt remove python3-pip



                              If you know for sure that you're fine with the older pip and prefer the system package you'll want to uninstall the newer one:



                              ~/.local/bin/pip3 uninstall pip



                              or failing that



                              sudo /usr/local/bin/pip3 uninstall pip






                              share|improve this answer












                              Installing pip from both apt and pip itself can cause this.



                              In my case, I used Ubuntu's pip package to install pipenv which then installed a newer copy of pip. Now because my shell runs Ubuntu's pip 9 script (to verify run which pip3) and my Python interpreter then imports the pip 10 module, the pip3 command fails. So I want to uninstall one of the two.



                              It's fair to assume you have the newer pip for a reason. In that case you want to uninstall the older pip like so:



                              sudo apt remove python3-pip



                              If you know for sure that you're fine with the older pip and prefer the system package you'll want to uninstall the newer one:



                              ~/.local/bin/pip3 uninstall pip



                              or failing that



                              sudo /usr/local/bin/pip3 uninstall pip







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered May 31 at 19:37









                              Jeff C

                              1




                              1






















                                  up vote
                                  0
                                  down vote













                                  My issue ended up being a mismatch between python3.6 and 3.7. The python3.6 installation put a link in /usr/bin/python3 -> /usr/bin/python3.6 even though the system had upgraded to python3.7.



                                  sudo apt purge python-pip
                                  sudo apt purge python3-pip
                                  sudo apt install python3.7 --reinstall
                                  cd /usr/bin
                                  sudo rm python3
                                  sudo ln -s python3.7 python3
                                  python3 --version
                                  pip3 --version





                                  share|improve this answer



























                                    up vote
                                    0
                                    down vote













                                    My issue ended up being a mismatch between python3.6 and 3.7. The python3.6 installation put a link in /usr/bin/python3 -> /usr/bin/python3.6 even though the system had upgraded to python3.7.



                                    sudo apt purge python-pip
                                    sudo apt purge python3-pip
                                    sudo apt install python3.7 --reinstall
                                    cd /usr/bin
                                    sudo rm python3
                                    sudo ln -s python3.7 python3
                                    python3 --version
                                    pip3 --version





                                    share|improve this answer

























                                      up vote
                                      0
                                      down vote










                                      up vote
                                      0
                                      down vote









                                      My issue ended up being a mismatch between python3.6 and 3.7. The python3.6 installation put a link in /usr/bin/python3 -> /usr/bin/python3.6 even though the system had upgraded to python3.7.



                                      sudo apt purge python-pip
                                      sudo apt purge python3-pip
                                      sudo apt install python3.7 --reinstall
                                      cd /usr/bin
                                      sudo rm python3
                                      sudo ln -s python3.7 python3
                                      python3 --version
                                      pip3 --version





                                      share|improve this answer














                                      My issue ended up being a mismatch between python3.6 and 3.7. The python3.6 installation put a link in /usr/bin/python3 -> /usr/bin/python3.6 even though the system had upgraded to python3.7.



                                      sudo apt purge python-pip
                                      sudo apt purge python3-pip
                                      sudo apt install python3.7 --reinstall
                                      cd /usr/bin
                                      sudo rm python3
                                      sudo ln -s python3.7 python3
                                      python3 --version
                                      pip3 --version






                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited Aug 9 at 12:18









                                      Stephen Rauch

                                      1,1546716




                                      1,1546716










                                      answered Aug 8 at 23:42









                                      Gregory Alan Bolcer

                                      413




                                      413






















                                          up vote
                                          -1
                                          down vote













                                          This worked for me:



                                          pip install --upgrade --user pip


                                          By install --upgrade, I mean whatever you're trying to install.






                                          share|improve this answer

























                                            up vote
                                            -1
                                            down vote













                                            This worked for me:



                                            pip install --upgrade --user pip


                                            By install --upgrade, I mean whatever you're trying to install.






                                            share|improve this answer























                                              up vote
                                              -1
                                              down vote










                                              up vote
                                              -1
                                              down vote









                                              This worked for me:



                                              pip install --upgrade --user pip


                                              By install --upgrade, I mean whatever you're trying to install.






                                              share|improve this answer












                                              This worked for me:



                                              pip install --upgrade --user pip


                                              By install --upgrade, I mean whatever you're trying to install.







                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered May 11 at 20:56









                                              Alex Jolig

                                              994




                                              994






























                                                   

                                                  draft saved


                                                  draft discarded



















































                                                   


                                                  draft saved


                                                  draft discarded














                                                  StackExchange.ready(
                                                  function () {
                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1025793%2frunning-pip3-importerror-cannot-import-name-main%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

                                                  Mont Emei

                                                  Province de Neuquén

                                                  Journaliste