EXPERT TIPS

Overview of Your Journey
- Setting the Stage
- Quickly: What is PIP?
- 1 – Installing Packages
- 2 – Updating Packages
- 3 – Uninstalling Packages
- 4 – Viewing Your Installed Packages
- 5 – Checking Out a Specific Package
- BONUS TIP – Checking for Missing Dependencies
- Wrapping Up
Setting the Stage
When learning Python, you are quickly introduced to pip – Python’s Package Installer. This is the main tool for installing __ external packages to your Python ecosystem.
One of the major selling points of Python is the rich ecosystem of third-party packages. As examples, the packages NumPy, Matplotlib, Pandas, Seaborn, and Scikit-Learn are all used in Data Science. In fact, building a data science project without using any of the above libraries would be a challenge (not in a good way!).
When I started with Python, I only knew the pip command:
pip install <package name>
Not bad, but pip has more commands up its sleeve. Had I known about these commands I would have saved hours of my time. Don’t make my mistake!
In this blog post, I will show you how to use the 5 most powerful pip commands.
Prerequisites: Except for having pip installed, you don’t need any previous knowledge of pip 😃
Quickly: What is Pip?
Pip is the main tool Python developers use to manage packages. This includes (as you will see soon):
- Downloading packages
- Updating packages
- Deleting packages
- Viewing installed packages
- Checking out a specific package
You should know: Pip is not the only way to manage packages with Python. In data science, it is also common to use the conda package manager to handle Python packages.
It’s nice to know the version of pip that is installed: To check this, you can run the command
python -m pip --version
Output: pip 21.2.3 from <path to pip>
It is in general good practice to keep pip updated. To get the latest version of pip, use the command:
python -m pip install --upgrade pip
1 – Installing Packages
The Basic Install
The first and most important use of pip is to install third-party packages. Say you want to install Seaborn to create sweet data visualizations. To do this, simply run the command:
python -m pip install seaborn
Output: Successfully installed seaborn-0.11.1 (and dependencies)
The command pip install
is the pip command you will use the most. It will by default install the latest available version of Seaborn. Also, it will automatically install any dependencies (other libraries that Seaborn depends on).
If you for some reason do not want the dependencies, then you can use the flag --no-deps
:
python -m pip install --no-deps seaborn
Output: Successfully installed seaborn-0.11.1 (and nothing else)
Installing a Specific Version
Sometimes though, you do not actually want to download the latest version of a package. This is typically to avoid breaking compatibilities with other packages. To download a specific version of a package, specify that with two equal signs:
python -m pip install numpy==1.20.0
Output: Successfully installed numpy-1.20.0
Installing From a Requirements File
Say you have made an awesome data science application in Python. Your application only uses the three packages:
- NumPy (version 1.21.1)
- Pandas (version 1.3.1)
- Seaborn (version 0.11.1)
The application is so cool that you have to share it with your friend. You send them the Python files. However, they can not run the Python files unless they also have installed NumPy, Pandas, and Seaborn. How tiresome would it be for your friend to install them (with the correct versions) one by one?
Luckily, there is a better way: A requirements.txt file. Make a file called requirements.txt in the project folder containing the three lines:
numpy==1.21.1
pandas==1.3.1
seaborn==0.11.1
When your friend receives your project, she can simply run the command:
python -m pip install -r requirements.txt
Output: Successfully installed cycler-0.10.0 kiwisolver-1.3.1 matplotlib-3.4.2 pandas-1.3.1 pillow-8.3.1 seaborn-0.11.1
You should know: The
-r
flag is shorthand for--requirements
, so you might see both used. Also, the filename requirements.txt is a convention. There is usually not a good reason to break the convention, though.
2 – Updating Packages
This is a short one. New versions of packages come around quite often. Say you want to upgrade to the newest version of NumPy. Then you can simply run the command:
python -m pip install -U numpy
Output: Successfully installed numpy-1.21.1
The flag -U
is shorthand for --upgrade
. Both are acceptable, and you can freely choose which one to use 👍
3 – Uninstalling Packages
Sometimes, you want to uninstall a package. This might be because the package creates conflicts with other packages.
Whatever the reason, this is simple with the command pip uninstall
. Try running the command:
python -m pip uninstall numpy
Output: Successfully uninstalled numpy-1.21.1
When executing the above command, you typically have to enter Y
and then press return to verify. This is pip asking: "Are you really sure you want to uninstall NumPy?"
I find pip’s helicopter parent approach annoying. If you feel the same, then you can use the flag -y
(shorthand for --yes
) to avoid getting asked:
python -m pip uninstall -y numpy
Output: Successfully uninstalled numpy-1.21.1
4 – Viewing Your Installed Packages
If you want to know the Python packages installed on your system, then use the command pip freeze
:
python -m pip freeze
Output:
appdirs==1.4.4
atomicwrites==1.4.0
attrs==21.2.0
beautifulsoup4==4.9.3
black==21.7b0
.
.
.
uvicorn==0.13.4
Werkzeug==2.0.1
The pip freeze
command shows every installed Python package with the corresponding version number.
Hmm… The format for the output seems familiar. This is precisely the format for the requirements.txt file I talked about before!
If you want to save your installed packages in a requirements file, then you can write:
python -m pip freeze > requirements.txt
This command creates a new file called requirements.txt and fills it with the output of pip freeze
. This gives you a short and sweet way of generating a requirements.txt file 🔥
You should know: We call
output > file
the standard output stream. This has nothing to do with pip and is (fun) terminal nonsense. In short, the syntax sends the output on the left to the file on the right.
5 – Checking Out a Specific Package
This is my personal favourite pip command. Say that you have NumPy installed.
Question 1: Which dependencies does NumPy have?
An even more difficult question:
Question 2: Which of your other packages depend on NumPy?
To get this information (and more!) you can use the command pip show
:
python -m pip show numpy
Output:
Name: numpy
Version: 1.21.1
Summary: NumPy is the fundamental package for array computing with Python.
Home-page: https://www.numpy.org
Author: Travis E. Oliphant et al.
Author-email:
License: BSD
Location: <path to numpy on my system>
Requires:
Required-by: seaborn, scipy, pandas, matplotlib
Read the information above carefully. The most important stuff is:
- The name of the package.
- The version that is installed.
- A summary of the package.
- The home page for the package.
- The location of the package on your system.
- Dependencies (written as Requires).
- Other packages that require this package (written as Required-by).
Notice that pip show
solves both our problems:
Answer 1: NumPy does not require any other external Python packages.
Answer 2: The packages Seaborn, SciPy, Pandas, and Matplotlib all require NumPy.
If you ever need some quick information about a package, then I highly recommend using pip show
😎
BONUS TIP – Checking for Missing Dependencies

Say that I have installed NumPy, Matplotlib, Pandas, and Seaborn. Yet, for some reason, I have managed to uninstall NumPy by mistake. Now Matplotlib, Pandas, and Seaborn will not work since they all depend on NumPy 😧
How do you find out what is wrong? Simply run the command pip check
:
python -m pip check
Output:
seaborn 0.11.1 requires numpy, which is not installed.
scipy 1.7.1 requires numpy, which is not installed.
pandas 1.3.1 requires numpy, which is not installed.
matplotlib 3.4.2 requires numpy, which is not installed.
The command pip check
will print out all missing dependencies of all Python packages. Now that you realize that NumPy is missing, you can simply install it back with pip install
.
Wrapping Up
You should now feel comfortable using pip for all your package needs. If you need to learn more about pip, then check out the pip documentation.
Like my writing? Check out my blog posts Type Hints, Formatting with Black, Underscores in Python, and 5 Dictionary Tips for more Python content. If you are interested in data science, Programming, or anything in between, then feel free to add me on LinkedIn and say hi ✋