00:00 In this lesson, you’ll perform some typical actions that you’ll do when working on a Python project. You’ll activate your virtual environment, install an external package, and list installed packages. Along the way, you’ll learn a bit more about project dependencies.
So this lesson brings the content of the former lessons together. You’ll use the terminal, a virtual environment, and
pip. That’s exciting, right?
00:26 Here I am in the project folder. Notice that the prompt has no prefixed environment name in parentheses. That means I currently don’t have any virtual environment activated.
Before activating the virtual environment, let’s check something first. When you run
python3 -m pip list, you can list the currently installed packages.
Here you can see that my system’s Python has
setuptools installed as packages that were grabbed via
pip. For you, there could be a different packages listed.
The important thing here is that these are the packages available for my system’s Python. We’ll come back to this in a bit. Now, let’s activate a virtual environment with
activate, and now there is
venv in parentheses at the beginning.
That means the virtual environment is activated. When I run the
pip list command again, then you can see this. There is no real difference in the listed packages yet.
To install an external package into a virtual environment, you must activate a virtual environment first. Then you use the
pip install command with the package name.
You used the
pip install command before, but with the
--upgrade option. So to just install a package that isn’t installed yet, you type
python3 -m pip install, and then the package name.
As an example, you’ll install the
requests package. The
requests package is used for making HTTP requests from a Python program. It’s extremely useful in a variety of domains, and many projects use it, but we won’t use it in this course.
02:19 It’s just an example for installing an external package.
In your terminal, you type the following:
python3 -m pip
install, and then the package name, which is
pip is installing the
requests package, you’ll see a bunch of output.
pip first tells you that it is collecting
requests. You see the specific filename that
pip is downloading and the progress bar.
After that, you see that
pip installs four more packages:
These packages are dependencies of the
requests package. That means that
requests requires these packages to be installed for it to work properly.
You can verify that these were requirements of
requests by typing
python3 -m pip show
pip show command displays information about an installed package, including the author’s name and an email and an homepage. It also lists that
pip is done installing
requests and its dependencies, you can run
pip list in your terminal again. Now
pip list shows the packages that you installed as well.
So when you install a package, more often than not, you also install some packages with it. That’s an important detail about installing packages with
04:10 These other packages are called dependencies or requirements. If you wouldn’t use a virtual environment for your projects, then your system’s Python packages would clutter quite fast with all these dependencies.
04:23 And this can be especially problematic, as different packages require different versions of their dependencies. So with a virtual environment, you minimize this problem tremendously.
To wrap this lesson up, deactivate your virtual environment and run the
pip list command again. So let’s type
python3 -m pip list.
04:50 And as you can see, your system’s Python package list stayed clean and tidy. All right, now that you know how to install packages, I’ll see you in the next lesson, where you’ll learn how to uninstall packages.
Become a Member to join the conversation.