So far, we stayed inside the core Python ecosystem. We either created our own code or used modules that are distributed with the standard Python distribution. However, there’s an enormous world out there of people using Python for anything you can think of. And many of these people share their code with the world in the form of packages. Let’s call such packages 3rd party packages.
This section of the tutorial introduces you to 3rd party Python packages, virtual environments, the pip package manager, and better alternatives that combine these two, like Pipenv and Poetry.
Table of contents
What is a 3rd party package?
If you followed the tutorial on this site, you already learned about creating your own Python packages. It’s a neat way of organizing our code in a directory structure. Python also allows us to create sharable packages, which can even be distributed to the entire world (for free) through the Python Package Index at PyPI.org.
There are close to 400,000 packages on that site as of writing this, and we can install anything we like from the Python package index with one simple command: pip install <package name>.
What is a virtual environment?
A Python venv (short for virtual environment) allows you to keep Python packages in an isolated location from the rest of your system. This is in contrast with the other option, installing them system-wide. Virtual environments have important advantages that we’ll go over first. I’ll show you exactly how to work with virtual environments in the following article.
After that, you need to learn how to install packages inside of a virtual environment, or system-wide. We do this with the pip install command.
Finally, virtual environments and pip come with a default Python installation. However, there are better tools these days. We’ll look at Pipenv, which combines package management and virtual environments into one tool that does some extra things for us as well.