Managing Python Dependencies Transcripts
Chapter: Managing Third-Party Dependencies With pip
Lecture: Installing & Updating pip

Login or purchase this course to watch this video and the rest of the course contents.
0:01 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.
0:08 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.
0:15 So all modern versions of Python 2 and Python 3 are going to include pip by default.
0:22 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
0:28 if pip is not available on your system yet. The first option to get a working pip install on your system
0:35 would be to upgrade to a more modern version of Python which is automatically going to include the latest version of pip.
0:41 Now, this would be my preferred option, but of course, if you're working with older legacy versions of Python
0:48 and you have a bunch of code running on them already, then that isn't really the best option.
0:54 So, option 2 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.
1:02 So in a nutshell, on macOS and Windows, you would have to download a so called bootstrap script, called get-pip.py.
1:10 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,
1:19 you would run it with the Python interpreter. So you would just go to the terminal and run something like Python get-pip.py
1:26 and the get pip script would then automatically install and set up pip on your system. Now, on most versions of Linux,
1:35 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.
1:42 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
1:50 with sudo apt install Python-pip, and running that command would add pip to your existing Python install.
1:58 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,
2:06 one resource that I can recommend to learn more about how to do this, is the Python packaging guide. You can find it at packaging.Python.org.
2:16 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
2:23 that came out when the Python release was prepared. But, pip and Python are actually fully independent,
2:30 so you can update pip without updating Python for example. Depending on the operating system that you're on,
2:37 the steps you need to take to update pip are slightly different. On macOS and Windows you would typically just use the pip command
2:45 to tell pip to upgrade itself, and I am going to give you a live demo of how to do that shortly.
2:51 On a Linux system where you are using the system package manager to manage your Python install, you would typically upgrade pip through that,
2:59 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.
3:07 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,
3:18 so I am running this command, sudo pip install --upgrade pip setuptools And what this is going to do, it's basically telling pip to upgrade itself.
3:29 Set up tools here is just another dependency for pip and part of the package management system in Python.
3:36 So typically, you would update both of them at the same time. I am going to go ahead and run this command now,
3:42 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
3:49 essentially everything is up to date. So any time you want to update pip to the latest version in the future,
3:55 you would just rerun that command, and then if there is an update pip would install it and upgrade itself to the latest version.


Talk Python's Mastodon Michael Kennedy's Mastodon