Introducing pip
00:00
pip
is a package manager for Python. It’s basically the package manager for Python, and it allows you to install and manage libraries and dependencies that aren’t part of Python standard library.
00:14 The concept of a package manager might be familiar to you if you’re coming from another programming language. JavaScript, for example, has nmp, Ruby has gem, the .NET platform has NuGet, Lua has LuaRocks, and Rust has Cargo.
00:31
Especially if you know one of these package managers, it’s important that you don’t think, “Oh, pip
is just exactly like, for example, npm,” because some of the package managers that you are seeing here, they fulfill way more tasks than just managing external packages.
00:50
pip
can be helpful for a bunch of tasks too, but to keep things basic in this course, you only need to remember this. The pip
package manager is there for you to install, update, or uninstall external packages.
01:05 External packages are third-party packages that are not part of the Python standard library.
01:13
One cool thing about pip
is that it comes with your Python installation right away. So if you have the terminal open, you can check it on Windows with python -m
pip --version
, and on macOS or Linux with python3
and the same command to see the version of pip
that’s installed on your system.
01:35
Running this command in the terminal shows you which version of pip
your standard Python installation works with.
01:45
Okay, so here you see me in my terminal on macOS. That’s why I will use the python3
as the command. If you’re on Windows, you need to use the python
command.
01:55
And when I type python3 -m pip
--version
and press Enter, then you see that the output says that my version is pip 22.0.3
from python 3.10
.
02:13
For you, both the pip
version and the Python version can be different, of course. My version of pip
seems a bit out of date. So since pip
is a Python package itself, you can use pip
to update pip
.
02:30
The beginning of the command to update pip
is the same like when you’re checking the version. It’s either python
or python3 -m pip
, ao that means you want to do something with pip
and then you use the install
command with the --upgrade
option.
02:45
Then you write pip
at the end because you want to upgrade the pip
package. Let’s have a look how this command works in action.
02:56
To upgrade pip
, you type python3 -m pip install
--upgrade pip
, and then you press Enter. And if a newer version of pip
is available, then it will be downloaded and installed. Otherwise, you’ll see a message indicating that the latest version is already installed.
03:18 This message usually says something like requirements already satisfied. Well, actually, let’s check what this message exactly says. You can press ↑ to traverse through your command history in the terminal.
03:33
That’s a convenient way to get a command you used before, and when you press Enter, you perform the command again. So here I have the python -m pip install --upgrade
command.
03:44
So if I press Enter, then you see that it says, indeed, Requirement
already satisfied
because we just updated pip
, so there is nothing for pip
to update there.
03:56
With pip install
, you install packages into your Python environment. So now that you upgraded your pip
version, your standard Python version works with the current pip
version.
04:08
Installing packages into your standard Python version is not ideal, though. It’s okay for packages like pip
that you want to use system-wide.
04:16 However, for other packages, you should be a bit more selective. Instead of installing them system-wide, you want to install them in something called virtual environment.
04:28 In the next lesson, you’ll learn about what a virtual environment is and how you can use it in Python.
Become a Member to join the conversation.