Installing and Updating Pip
00:00 Before we continue, I want to make sure you actually have a working pip install at this point, and that it’s fully up to date. So let’s talk about installing pip if it’s not already on your system and then also how you can upgrade to the latest version of pip.
So all modern versions of Python 2 and Python 3 are going to include pip by default. Now of course that doesn’t really help you if the
pip command doesn’t work in your system right now, so let’s talk about what you can do if pip is not available on your system yet.
00:31 The first option to get a working pip install on your system would be to upgrade to a more modern version of Python which is automatically going to include the latest version of pip.
00:40 Now, this would be my preferred option, but of course, if you’re working with older legacy versions of Python and you have a bunch of code running on them already, then that isn’t really the best option.
So, option two would be to add pip to your existing Python install, and that is definitely possible, I am going to show you how to do that now. So in a nutshell, on macOS and Windows, you would have to download a so called bootstrap script, called
And you would download that through a browser or through a command line tool like
curl, and once you’ve downloaded the
get-pip script, you would run it with the Python interpreter.
So you would just go to the terminal and run something like
python get-pip.py and the
get-pip script would then automatically install and set up pip on your system.
01:31 Now, on most versions of Linux, especially if you’re using a version based on Debian Linux like Ubuntu, you would actually go through the system package manager to install pip.
To do that, you would first run a command like
sudo apt update to refresh your system’s package manger and then you would follow up with
sudo apt install python-pip, and running that command would add pip to your existing Python install.
01:57 Now adding pip to an existing Python install is a little bit fiddly, there are a couple of edge cases you need to look out for, one resource that I can recommend to learn more about how to do this, is the Python packaging guide.
02:11 You can find it at packaging.python.org. Let’s make sure you’re running an up to date version of pip on your system. Modern versions of Python will always include the latest pip version that came out when the Python release was prepared.
02:25 But, pip and Python are actually fully independent, so you can update pip without updating Python for example. Depending on the operating system that you’re on, the steps you need to take to update pip are slightly different.
02:40 On macOS and Windows you would typically just use the pip command to tell pip to upgrade itself, and I am going to give you a live demo of how to do that shortly.
02:50 On a Linux system where you are using the system package manager to manage your Python install, you would typically upgrade pip through that, so you wouldn’t actually use the pip command to upgrade pip but you would just tell the system package manager to update your install of pip.
I am going to give you a live demo of how that upgrade process works. So I am back here in my macOS terminal and I’ve prepared this command here, so I am running this command,
sudo pip install --upgrade pip setuptools.
03:23 And what this is going to do, it’s basically telling pip to upgrade itself. Set up tools here is just another dependency for pip and part of the package management system in Python.
So typically, you would update both of them at the same time. I am going to go ahead and run this command now, so because I am running this with
sudo, I need to enter my account password, okay, so this worked, and what pip is telling us here is that essentially everything is up to date.
03:51 So any time you want to update pip to the latest version in the future, you would just rerun that command, and then if there is an update pip would install it and upgrade itself to the latest version.
I am using my office laptop and while I update pip I get the following error on the command line
Could not install packages due to an EnvironmentError: [WinError 5] Access is denied: ‘C:\Users\my_company_id\AppData\Local\Temp\pip-uninstall-1ua61abl\pip.exe’
Consider using the
--user option or check the permissions.
What is the workaround for this?
Hi, I am currently on Ubuntu 20.04, and it seems that Python2 is not a standard part of the system equipment. However, to install
pip I had to use
sudo apt-get install python3-pip (the native linux python in this case being python 3.8.2)
where do you discuss adding a directory to PATH to os x? Can one use TextMate or TextEdit?
WARNING: The scripts pip, pip2 and pip2.7 are installed in ‘/Users/<my name>/Library/Python/2.7/bin’ which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use –no-warn-script-location.
Error messages about testresources
pip3 already installed on my Ubuntu 20.4. Running
sudo pip3 install --upgrade pip setuptools gave an error:
RROR: launchpadlib 1.10.13 requires testresources, which is not installed. But it also said
Successfully installed pip-20.2.4 setuptools-50.3.2.
I installed the testresources
sudo apt install python3-testresources and reran
sudo pip3 install --upgrade pip setuptools. This time no errors, but it said that everything was already up-to-date. So why the error?
Hi.. Is it true that it’s always better to use:
python -m pip3 install request rather than using
pip3 install request ? to avoid accidently calling pip (or other libraries) golbally?
@mhdhabboub Yes, that’s a great habit. Here’s an article that goes into more detail about why: snarky.ca/why-you-should-use-python-m-pip/
@mhdhabboub One small note about the command. You will always use
-m pip without the version number. This is Python syntax for calling a module/library and the library’s name is
pip. However, you may need to use a version specifier on
python depending on how your system is set up. For instance,
python3 -m pip install ... Also, note that the famous library for doing web requests is called
requests with an
s at the end :)
Become a Member to join the conversation.
mikemu1 on May 8, 2020
Why is sudo required on MacOS?