2

I am trying to upgrade pip from version 7.1.2 to 8.0.2 But I am not able to upgrade it due to some errors. I ran the following command.

user@ubuntu:~/devstack$ pip install --upgrade pip

I am getting following Traceback errors:

Screenshot of output
Screenshot of output continue

Please let me know how can I make it work.

1

2 Answers 2

7

You can either upgrade pip globally using sudo:

sudo pip3 install --upgrade pip
sudo pip2 install --upgrade pip

Or you can upgrade it for your user only using the --user option:

pip3 install --upgrade --user pip
pip2 install --upgrade --user pip

Note that I upgrade both pips for Python 2 and Python 3. It's important to upgrade the version for Python 3 first, because the one you upgrade last will later be accessible through pip, which must be pip2 by default.


Important update:

As of pip version 10 (I think), the pip/pip3 command is broken, due to a change in the package structure which is not compatible with the launch scripts provided from the python-pip/python3-pip packages from apt. See Error after upgrading pip: cannot import name 'main' on Stack Overflow for details.

Quick fix: Don't run pip/pip3 any more, but instead always use python -m pip/python3 -m pip, which will not use the now incompatible executable scripts provided from your system's package manager, or don't upgrade your pip/pip3 version to 10 or higher.

8
  • 1
    Note that if you choose to use sudo, you will overwrite the system Pip, which is likely to be owned by the package manager – this can lead to problems in the future, if the package manager notices your changes.
    – ash
    Jul 29, 2018 at 10:05
  • @Josh I don't think so. A sudo pip install/upgrade would end up in /usr/local/bin, the package manager's python-pip is placed in /usr/bin. They can peacefully coexist, just the one in local will take precedence due to the PATH order.
    – Byte Commander
    Jul 29, 2018 at 11:41
  • Oh, cool – last time I tried sudo pip it borked my install, but if it works now, then that's awesome.
    – ash
    Jul 29, 2018 at 14:51
  • I upgraded pip3 from 9.0.1 to 18.0 using sudo pip3 install --upgrade pip. As @ByteCommander says, pip3 works due to the PATH order, but ... If I try /usr/bin/pip3 --version in Ubuntu 16.04, I get the response, "Traceback (most recent call last): File "/usr/bin/pip3", line 9, in <module> from pip import main" The, I get a crash window popping up.
    – Diagon
    Aug 24, 2018 at 23:52
  • @Diagon There is some incompatibility between the scripts used to launch pip from the command line and the updated internal pip python packages starting with version 10. See my edited answer.
    – Byte Commander
    Aug 25, 2018 at 11:18
0

I also run into this problem when I wanted to upgrade system pip pip3 from 9.0.1 to 19.2.3.

After running pip3 install --upgrade pip, pip version becomes 19.2.3. But main() has been moved in pip._internal in the latest version, which leaves pip3 broken.

So in file /usr/bin/pip3, replace line 9: from pip import main with from pip._internal import main. The issue will be fixed, works the same for python2-pip. (Tested on Ubuntu 18.04 distribution)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .