A convenient thing about
pip install is that you can chain package names. So you use the
pip install command, and then you have like the package-name-1, the package-name-2, the package-name-3, and so on.
This text file is commonly named
requirements.txt. Then you can share this file with your friend, and your friend can use this file to install all requirements with the
pip install command and the
I’m currently in the project directory with an activated virtual environment. First, let’s have a look what packages are installed by running
pip list. So currently, there are
I’ll show you the capabilities in a moment. Let’s install them first. To install both packages at the same time, You type
python3 -m pip install
requests and then, with a space in between,
rich and then press Enter.
Isn’t this amazing? Depending on your terminal capabilities, the output might look a bit different. So we won’t go into detail about the packages you install with
pip in this course, but I’ll mention some Real Python resources for both Requests and Rich at the end of this course.
But I wanted to show you how to run Rich because we’ll try it out without an activated virtual environment in a moment. Okay, let’s move on. When you type
clear and press Enter, you clear your terminal window.
As you know, when you installed
rich, you probably didn’t just install the packages itself, but also their dependencies. To see them, you run
pip list, but there’s another command that you can use.
You can see that there are equal signs (
==) there. This syntax lets
pip know exactly what versions to use when installing requirements, and the version of a package is actually a quite important detail. When you work with others on a project, you want to make sure that you are all working with the same package version, for example. Otherwise, an update might introduce a change that makes your code break, and you need to adjust your Python code accordingly.
03:45 So that’s why it’s even a good idea to freeze your requirements for yourself as well, even when you’re not working with others. You always want to develop in an environment where you know exactly which versions of your packages you’re working with. Okay, enough rambling.
I think you got the message. This output of
pip freeze with the version numbers is important. To save this output in a file, you can use the caret symbol (
>). With the caret, you can redirect the output of a command into a file.
So you can run this command every time when you install new packages for your project, and therefore you change your requirements for your project, and you can run
freeze again and save the output in the requirements file, so that way you have your requirements frozen for the current state of your project.
You can look at the content of a file with the
cat command. So if you type
cat requirements.txt, then you see the content of the requirements file. Look, this is exactly the output of
pip freeze, so it worked. Perfect. With
clear, I can clear a terminal again.
Become a Member to join the conversation.