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.
ajackson54 on Sept. 7, 2024
I’m having problems activating my venv module. I get a ‘module venv can not be loaded. For more info run ‘Import Module venv’ message. I tried to add venv to my path but I got the same message.
Martin Breuss RP Team on Sept. 9, 2024
@ajackson54 are you on a Linux system? Some of the Python installations on Linx come without the venv
module installed.
If that’s the case, then you’ll have to install it separately:
$ sudo apt install python3-venv
It’s an annoying edge case situation, I’m not sure why some Linux distributions decided to remove venv
from the standard library (probably something about reducing size).
You could also check out the Python launcher for UNIX project that tries to solve it, or AFAIK if you use VS Code it has some built-in plugin that notifies you if venv
is missing and installs it for you.
Martin Breuss RP Team on Sept. 9, 2024
@dakshnavenki not entirely sure what was happening there for you, but it’s not a big deal if your pip
version is a few numbers behind.
You could try to force the update through a reinstall:
$ python -m pip install --upgrade --force-reinstall pip
ajackson54 on Sept. 12, 2024
Hello, Martin – thanks for your response. I’m on Windows, not Linux. In my venv folder I found Include, Libs, and Scripts folders. There is also a pyvenv.cfg configuration file. Inside the Scripts folder there are python and pythonw applications. Is my logic correct in thinking that there should be an activate module in there? I also looked at the Python Launcher for UNIX as you suggested. It was pretty detailed so I’ll look at it closer after this post. I’ve been bogged down too long on this problem, so, if I don’t find a solution today, I’ll put it aside and give myself a half hour a day searching for a solution until I find one. I’ve completed 97% of my Basics learning path and I’m anxious to complete it.
Martin Breuss RP Team on Sept. 13, 2024
@ajackson54 on Windows the structure of your virtual environment is slightly different. Like you said, you should find a file called activate
(and also activate.bat
and Activate.ps1
) inside your Scripts\
folder.
If neither of these files are there, then just delete your virtual environment and recreate it.
If you have the file, then you should be able to activate the virtual environment by running:
PS> venv\Scripts\activate
Make sure that you’re in the same folder that contains the venv\
folder that you generated.
Become a Member to join the conversation.
dakshnavenki on Sept. 13, 2023
Hello, I am in Windows environment, using python 3.10 and pip version is 22.0.4 and when trying to upgrade my pip using the install command shown in this tutorial, it says requirement already satisfied without installing pip 23.x. How to fix this issue and how to upgrade my pip to 23.x? Please help.