893

I'm able to update pip-managed packages, but how do I update pip itself? According to pip --version, I currently have pip 1.1 installed in my virtualenv and I want to update to the latest version.

What's the command for that? Do I need to use distribute or is there a native pip or virtualenv command? I've already tried pip update and pip update pip with no success.

Falko
  • 17,076
  • 13
  • 60
  • 105
zakdances
  • 22,285
  • 32
  • 102
  • 173
  • 102
    `pip install --upgrade pip`? It's just another PyPI package. – Cairnarvon Mar 05 '13 at 10:34
  • 1
    That command gives me "/Users/zak/MyProject/venv/bin/pip install: error: no such option: --update" – zakdances Mar 05 '13 at 10:36
  • 4
    It's `--upgrade`, not `--update`, sorry. I edited my post immediately, but you must have seen it at exactly the wrong time. – Cairnarvon Mar 05 '13 at 10:37
  • 2
    @Cairnarvon is the command different for `pip3`? I am trying for pip3 but it just tells me it can't find it and then goes ahead complains AGAIN that its not up to date...when it doesn't even let me update/upgrade it! – Charlie Parker Jan 10 '17 at 23:47
  • This is really not that complicated. The number of undeleted answers here is simply not justified. – Karl Knechtel Jul 22 '23 at 08:14

23 Answers23

1501

pip is just a PyPI package like any other; you could use it to upgrade itself the same way you would upgrade any package:

pip install --upgrade pip

On Windows the recommended command is:

py -m pip install --upgrade pip
starriet
  • 2,565
  • 22
  • 23
Cairnarvon
  • 25,981
  • 9
  • 51
  • 65
  • 65
    Under Windows I had a permissions issue attempting to upgrade pip using pip. Instead I used easy_install to upgrade: `easy_install pip` – bsa Nov 05 '13 at 06:25
  • 9
    When I did this pip seemed to upgrade (1.1 -> 1.4), but when I do "pip --version" it is still showing the old version 1.1. Tried to deactivate and activate the virtualenv again but it's still showing the old version. – Zitrax Dec 02 '13 at 11:46
  • 50
    On Windows probably is better to use command like that: `python -m pip install --upgrade pip` to avoid running pip.exe from scripts directory. – bialix Feb 19 '14 at 14:47
  • Please edit your "dangerous" suggestion; this command may leave user's Windows without any `pip` installed. – ankostis Apr 10 '16 at 11:50
  • I know it's an old issue, bu to fix the problem faced by Zitrax, I shoud do : easy_install pip and then /usr/local/bin/pip --version to get the version – jmcollin92 Jun 30 '16 at 14:46
  • @Zitrax, go to the VE folder, find out the Scripts folder, and open cmd there. Then try executing this command. Otherway can be (I am not sure) replacing pip under /VE/Scripts with the global one. – Pikesh Prasoon Apr 05 '18 at 09:31
  • FWIW, I had to do right click, "Run as administrator" for Command Prompt on Windows to get this to work, otherwise had a permissions error – Aaron Mar 10 '19 at 19:03
  • Or use the **python -m pip install --upgrade --user pip** which tells Pip to install packages into a special user-specific directory, that, by default, is on your Python module search path. – athina.bikaki Mar 31 '19 at 08:25
  • For some other problems, once you upgrade pip, but still can't upgrade some other packages, this might help: python -m pip install --upgrade pip setuptools – Aleksandar Pavić Jun 18 '19 at 11:54
  • I had the same problem as @Zitrax on Windows: the upgrade seemed to work find with `python -m pip install -U pip` but when doing `pip --version` it still showed the old version. I think it comes from a permission problem that prevent to uninstall the old version. I solved it by upgrading virtualenv so that the latest version of pip would be used when creating the environment and created a new environment. – Sarah N Jun 21 '19 at 08:06
108

The more safe method is to run pip though a python module:

python -m pip install -U pip

On windows there seem to be a problem with binaries that try to replace themselves, this method works around that limitation.

Nate Anderson
  • 18,334
  • 18
  • 100
  • 135
Janusz Skonieczny
  • 17,642
  • 11
  • 55
  • 63
  • 13
    This is now what pip itself recommends, if it detects a newer version of itself. – tephyr May 29 '16 at 21:51
  • 5
    I believe the reason this is safer is because on some OSes (Windows), just running pip directly can create a file lock on the executable, which would prevent updating it. By calling Python and telling it to load the module directly, you avoid accessing the executable. – jpmc26 Jul 15 '16 at 15:44
  • 1
    You have to run the command prompt in administrator mode to get this to work. I tried several other suggestions and nothing worked until I restarted the command prompt window in admin mode, then this command worked perfectly. – DaveN59 Aug 06 '18 at 20:01
55

In my case my pip version was broken so the update by itself would not work.

Fix:

(inside virtualenv):easy_install -U pip
jmoz
  • 7,846
  • 5
  • 31
  • 33
  • Same here, that's the only way that works for me on Debian. Using python or pip to upgrade pip from within the virtualenv would fail because it refused to uninstall existing pip sitting outside the venv. – user3748764 Sep 28 '17 at 11:37
  • Running this shown me a lot of stuff including `Download error on https://pypi.python.org/simple/pip/: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590) -- Some packages may not be found!` which wasn't displayed when running --upgrade. And it's likely the reason why installing any pip package is failing and why upgrading pip through pip is failing as well, SSL seems broken. – Vadorequest Jun 04 '18 at 21:11
  • Lifesaver, thank you. Tried everything else and only this worked on Windows 10. – Milo Persic Aug 16 '20 at 00:59
  • Worked flawlessly on Linux Mint – Scriddie May 03 '21 at 09:26
19

I tried all of these solutions mentioned above under Debian Jessie. They don't work, because it just takes the latest version compile by the debian package manager which is 1.5.6 which equates to version 6.0.x. Some packages that use pip as prerequisites will not work as a results, such as spaCy (which needs the option --no-cache-dir to function correctly).

So the actual best way to solve these problems is to run get-pip.py downloaded using wget, from the website or using curl as follows:

 wget https://bootstrap.pypa.io/get-pip.py -O ./get-pip.py
 python ./get-pip.py
 python3 ./get-pip.py

This will install the current version which at the time of writing this solution is 9.0.1 which is way beyond what Debian provides.

 $ pip --version
 pip 9.0.1 from /home/myhomedir/myvirtualenvdir/lib/python2.7/dist-packages (python 2.7)
 $ pip3 --version
 pip 9.0.1 from /home/myhomedir/myvirtualenvdir/lib/python3.4/site-packages (python 3.4)
Eamonn Kenny
  • 1,926
  • 18
  • 20
  • 4
    helpful for when `pip install --upgrade pip` failed – Andrew Bowman May 18 '18 at 15:41
  • 1
    If I could upvote this answer a few times I would. This just solved an issue where pip 9.x failed with an SSL error by updating to pip 10.x. See https://stackoverflow.com/questions/25981703/pip-install-fails-with-connection-error-ssl-certificate-verify-failed-certi#29751768 – Keith John Hutchison May 26 '18 at 22:15
  • 1
    Well, if you have upvoted it even once I'll be happy. My answers are usually found from an hour or two of hunting and years of experience. Can't say the same for my questions? People can be really mean! :) – Eamonn Kenny May 28 '18 at 12:46
15

for windows,

  • go to command prompt
  • and use this command
  • python -m pip install -–upgrade pip
  • Dont forget to restart the editor,to avoid any error
  • you can check the version of the pip by
  • pip --version
  • if you want to install any particular version of pip , for example version 18.1 then use this command,
  • python -m pip install pip==18.1
Rohan Devaki
  • 2,931
  • 1
  • 14
  • 22
13

In case you are using venv any update to pip install will result in upgrading the system pip instead of the venv pip. You need to upgrade the pip bootstrapping packages as well.

python3 -m pip install --upgrade pip setuptools wheel
Neuron
  • 5,141
  • 5
  • 38
  • 59
dre-hh
  • 7,840
  • 2
  • 33
  • 44
  • after successful install python list still shows older version of the pip. How to point latest version to current environment – Arpan Saini Oct 07 '20 at 03:26
  • 1
    Should I do `$HOME/venv/bin/python3` or just `python3` ? – alper May 05 '21 at 20:33
  • 1
    if you have activated venv with source /path/to/myvenv/bin/activate, then just use `python3` or even just `python`. if it s not activated run `/path/to/myvenv/bin/python3` – dre-hh May 06 '21 at 11:49
  • 1
    `python3 -m pip install --upgrade pip setuptools wheel /usr/bin/python3: No module named pip` – Eugene Gr. Philippov Jul 06 '21 at 11:45
  • 1
    Some distros ship a python3 version without pip. The easiest way is to use ensurepip and bootstrap pip into the same python installation. `python3-m ensurepip --upgrade` https://docs.python.org/3/library/ensurepip.html – dre-hh Jul 06 '21 at 21:59
  • "In case you are using venv any update to pip install will result in upgrading the system pip instead of the venv pip." - No; you just have to make sure that you use the venv's Python for the command. If you use the venv's `pip` command wrapper, this should be automatic, too (it doesn't work on Windows, but that's because Windows won't allow running executables to replace their own file). Just make sure the venv is activated. – Karl Knechtel Jul 22 '23 at 08:12
9
pip install --upgrade pip

In UBUNTU 18.04 I got the following error when I execute the above command:

ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/local/bin/pip'
Consider using the `--user` option or check the permissions.

The below command solves my problem:

pip install --upgrade pip --user
Parzival
  • 2,051
  • 4
  • 14
  • 32
Hasinur
  • 194
  • 1
  • 6
8

Upgrading pip using 'pip install --upgrade pip' does not always work because of the dreaded cert issue: There was a problem confirming the ssl certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version

I like to use the one line command for virtual envs:

curl https://bootstrap.pypa.io/get-pip.py | python -

Or if you want to install it box wide you will need

curl https://bootstrap.pypa.io/get-pip.py | sudo python -

you can give curl a -s flag if you want to silence the output when running in an automation script.

rouble
  • 16,364
  • 16
  • 107
  • 102
5

To get this to work for me I had to drill down in the Python directory using the Python command prompt (on WIN10 from VS CODE). In my case it was in my AppData\Local\Programs\Python\python35-32 directory. From there now I ran the command...

python -m pip install --upgrade pip

This worked and I'm good to go.

Neuron
  • 5,141
  • 5
  • 38
  • 59
Sean
  • 427
  • 4
  • 4
2

For linux

python3 -m pip install --upgrade pip

For windows:

  1. Type Command Prompt in the Windows search box

  2. In the Command Prompt, type cd\

  3. Press Enter, and you’ll see the drive name C:\>

  4. Locate your Python application path, which is the folder where you originally installed Python

    Here is an example of a Python application path:

    C:\Users\Ron\AppData\Local\Programs\Python\Python39
    
  5. Once you retrieved the Python application path, type the following command in the Command Prompt:

    cd followed by your Python application path

    For our example:

    C:\>cd C:\Users\Ron\AppData\Local\Programs\Python\Python39
    
  6. Press Enter

  7. Type python -m pip install --upgrade pip and press Enter

Neuron
  • 5,141
  • 5
  • 38
  • 59
Dev
  • 503
  • 5
  • 17
1

In my case this worked from the terminal command line in Debian Stable

python3 -m pip install --upgrade pip
zx485
  • 28,498
  • 28
  • 50
  • 59
1

Open Command Prompt with Administrator Permissions, and repeat the command:

python -m pip install --upgrade pip
Grant Miller
  • 27,532
  • 16
  • 147
  • 165
MRamzan
  • 161
  • 2
  • 7
1

pip version 10 has an issue. It will manifest as the error:

ubuntu@mymachine-:~/mydir$ sudo pip install --upgrade pip
Traceback (most recent call last):
  File "/usr/bin/pip", line 9, in <module>
    from pip import main
ImportError: cannot import name main

The solution is to be in the venv you want to upgrade and then run:

sudo myvenv/bin/pip install --upgrade pip

rather than just

sudo pip install --upgrade pip
Calaf
  • 10,113
  • 15
  • 57
  • 120
1

I was in a similar situation and wanted to update urllib3 package. What worked for me was:

pip3 install --upgrade --force-reinstall --ignore-installed urllib3==1.25.3
Avik Aggarwal
  • 599
  • 7
  • 28
1
some_venv>python.exe -m install --upgrade pip
some_venv>pip -V
M--
  • 25,431
  • 8
  • 61
  • 93
  • While this code may solve the question, [including an explanation](//meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. – Yunnosch Aug 30 '23 at 21:45
  • And maybe you want to apply the formatting skills which your other posts exhibit... – Yunnosch Aug 30 '23 at 21:45
0

I had installed Python in C:\Python\Python36 so I went to the Windows command prompt and typed cd C:\Python\Python36 to get to the right directory. Then entered the python -m install --upgrade pip all good!

Neuron
  • 5,141
  • 5
  • 38
  • 59
Walt
  • 9
  • 2
0

On my lap-top with Windows 7 the right way to install latest version of pip is:

python.exe -m pip install --upgrade pip
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
MiloshB
  • 151
  • 1
  • 2
  • 10
0

First, do this:

sudo apt install python3-pip python-setuptools-doc

Then, as a non-root user (NEVER, never run pip* as root!):

# N.B. bash shell works for this, I have never tested with other shells!
. ....your_virtualenv_folder/bin/activate
pip3 install -U pip

Note: -U is a synonym for --upgrade, as far as I know.

Neuron
  • 5,141
  • 5
  • 38
  • 59
Eugene Gr. Philippov
  • 1,908
  • 2
  • 23
  • 18
  • If you are using a virtualenv anyway, there is no reason to use the system package manager to install Pip in the system Python. When a virtualenv is created, it will automatically bootstrap Pip if the source Python didn't have it. If your distro didn't include Pip with the system Python, that is for your protection; you're meant to let the system package manager manage that Python directly rather than opening it up to any arbitrary package using Pip. – Karl Knechtel Jul 22 '23 at 08:06
-1

Single Line Python Program
The best way I have found is to write a single line program that downloads and runs the official get-pip script. See below for the code.

The official docs recommend using curl to download the get-pip script, but since I work on windows and don't have curl installed I prefer using python itself to download and run the script.

Here is the single line program that can be run via the command line using Python 3:

python -c "import urllib.request; exec(urllib.request.urlopen('https://bootstrap.pypa.io/get-pip.py').read())"

This line gets the official "get-pip.py" script as per the installation notes and executes the script with the "exec" command.

For Python2 you would replace "urllib.request" with "urllib2":

python -c "import urllib2; exec(urllib2.urlopen('https://bootstrap.pypa.io/get-pip.py').read())"

Precautions
It's worth noting that running any python script blindly is inherently dangerous. For this reason, the official instructions recommend downloading the script and inspecting it before running.

That said, many people don't actually inspect the code and just run it. This one-line program makes that easier.

FistOfFury
  • 6,735
  • 7
  • 49
  • 57
-1

I had a similar problem on a raspberry pi.

The problem was that http requires SSL and so I needed to force it to use https to get around this requirement.

sudo pip install --upgrade pip --index-url=https://pypi.python.org/simple

or

sudo pip-3.2 --upgrade pip --index-url=https://pypi.python.org/simple/
user391339
  • 8,355
  • 13
  • 58
  • 71
-1

Head to your command prompt and type the following:

python -m pip install --upgrade pip
-1

While updating pip in virtual env use full path in python command

Envirnments folder struture

myenv\scripts\python

h:\folderName\myenv\scripts\python -m pip install --upgrade pip

-4

In linux

I will update with this code

sudo -H pip3 install --upgrade pip
Netwons
  • 1,170
  • 11
  • 14