24

I am new to Linux and Ubuntu.

I was trying to upgrade pip but ran into this...

$ sudo pip install --upgrade pip
Cannot fetch index base URL https://pypi.python.org/simple/
Downloading/unpacking pip from https://pypi.python.org/packages/py2.py3/p/pip/pip-7.1.0-py2.py3-none-any.whl#md5=b108384a762825ec20345bb9b5b7209f
  Downloading pip-7.1.0-py2.py3-none-any.whl (1.1MB): 1.1MB downloaded
Installing collected packages: pip
  Found existing installation: pip 1.5.4
    Not uninstalling pip at /usr/lib/python2.7/dist-packages, owned by OS
Successfully installed pip
Cleaning up...

Any idea why?

Zanna
  • 72,312
Spencer Lee
  • 343
  • 1
  • 2
  • 4

11 Answers11

23

Try install it with easy_install:

easy_install -U pip
Jens Erat
  • 5,131
  • 7
  • 33
  • 37
NamPNQ
  • 341
7

I had the same issue for a long time and figured out the solution today. When you install pip via python-pip, you download from the deprecated Linux server. You should download from the python server. To solve this, do the following:

sudo apt-get purge pip
sudo apt-get install python-setuptools
sudo apt-get install python-dev 
sudo easy_install pip 
pip install pip --upgrade 
xofer
  • 568
4

This is caused by a conflict between a version of pip provided by a system package, like python-pip, and a version provided by PyPI through pip itself.

To fix this, simply remove python-pip with sudo apt-get purge python-pip.

If you had already used the old version of pip to install a newer version, this should leave the updated version in /usr/local/bin. If not, you can install the most recent version of Pip from scratch with:

Pip for Python 2.7:

curl --silent --show-error --retry 5 https://bootstrap.pypa.io/get-pip.py | sudo python2.7

Pip for Python 3.x:

curl --silent --show-error --retry 5 https://bootstrap.pypa.io/get-pip.py | sudo python3
Cerin
  • 6,923
3

Edit:

pip install -U pip

or

pip install --upgrade pip

-U is shorthand for --upgrade.


Old answer:

The apt system and PyPI uses two different mechanisms.

In Ubuntu's repositories many modules of python are available as packages, but they are not much in numbers as compared to PyPI (The Python Package Index). To remain consistent about upgrading a package you need to consider the method you have used initially used to install it.

So if you have installed a package (module) from PyPI using pip then you should used pip to upgrade the package from PyPI (including pip itself). On the other hand if you have used apt system to install a module (as package) you need to use apt to upgrade that again.

In a nutshell, run the following to upgrade python-pip to the latest version :

sudo apt-get install python-pip
heemayl
  • 93,925
2

Actually, you can edit your 'pip' script:

from root:

$ which pip  # -> prints 'pip' location

$ nano `which pip` # -> open with your editor, note the backticks!

replace the __requires__ with your latests pip version like:

__requires__ = 'pip==7.1.2'

than edit line with 'load_entry_point' call to:

load_entry_point(__requires__, 'console_scripts', 'pip')()

and:

$pip -V
pip 7.1.2 from /usr/local/lib/python2.7/dist-packages (python 2.7)

also, i have to update my setuptools package, to install some packages.

s0rg
  • 21
1

Use this link to upgrade. Basically:

  1. Download the file get-pip.py
  2. run python get-pip.py
Manish
  • 11
1

If python-pip installed from apt repositories with sudo user - run sudo -H install --upgrade pip , same for installing PIP modules .

Here the output from my console on 16.04

..... Successfully installed requests
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
:~$ pip install --upgrade pip
Collecting pip
  Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 672kB/s 
Installing collected packages: pip
Successfully installed pip-8.1.1
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
:~$ sudo -H pip install --upgrade pip
Collecting pip
  Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 692kB/s 
Installing collected packages: pip
  Found existing installation: pip 8.1.1
    Not uninstalling pip at /usr/lib/python2.7/dist-packages, outside environment /usr
Successfully installed pip-9.0.1
:~$ 

also see What is the -H flag for pip? https://stackoverflow.com/questions/28619686/what-is-the-h-flag-for-pip

1

Try running sudo -H pip3 install --upgrade pip to upgrade your pip3 (for Python 3). Conversely, you can do sudo -H pip2 install --upgrade pip to upgrade pip as well (for Python 2).

1

I ran into this problem when working on a remote machine I was ssh'd into. I had just installed python 3, and was unable to get pip to upgrade, even though I'd attempted to upgrade via both pip AND apt-get.

Logging out of the remote server and logging back in fixed it.

0

I got similar problem on upgrading pip 9.0.3 to 18.0 version.

So on upgrading first uninstallation happens and then the latest version is installed. However, I found that on your first attempt it says "successfully uninstalled pip-9.0.3"

On subsequent attempts, we get the same error. This is because the pip-9.0.3 is uninstalled. As with the accepted answer, I installed pip as an admin in my windows 10 system, got thee latest version and then all was well.

Hope this helps.

Eswar
  • 121
0

I'm only a beginner so I'm not sure but probably is something related to the differences between python 2 and 3. I think that is not necessary to be a superuser but you can do it easily using pip3 instead of pip also to upgrade pip : pip3 install --upgrade pip

NBee
  • 11