Pip Install: How To Install and Remove Packages

Pip install is the command you use to install Python packages with the Pip package manager. If you’re wondering what Pip stands for, the name Pip is a recursive acronym for ‘Pip Installs Packages.’ There are two ways to install Python packages:

  1. Manual installation
  2. Using a requirements.txt file that defines the required packages and their version numbers.

But before we start, let’s make sure pip itself is installed!

Installing Pip

Good news; chances are that Pip is already present on your system. Most Python installers also install Pip. Pip is already installed if you are using Python 2 >=2.7.9 or Python 3 >=3.4 downloaded from python.org. If you are working in a virtual environment, pip also gets installed for you.

So before you try to install Pip, make sure it’s not already present on your system. Open a terminal (Linux/MacOS) or a Windows shell, and type in the following command:

pip help

If the pip command gives an error, try pip3 instead. On some systems, Python 2 and 3 can be installed next to each other. On those systems, pip is often installed under the name pip3:

pip3 help

If that didn’t work either, you can try the pip module that is built into most modern Python installations:

python3 -m pip help

If that failed too, you need to install it yourself, so let’s take a look at how you can manually install it.

Install Pip on Windows and MacOS

On Windows and MacOS, you can download a Python script to install pip, called get-pip.py. Download the file and run it with Python from a command prompt or terminal window:

python3 get-pip.py

Make sure you are in the directory where the script was downloaded.

Install Pip on Linux

You can install pip with the apt package manager on Debian, Ubuntu, Linux Mint, and other Debian derivatives. It’s the most recommended method and ensures your system will stay in a consistent state.

$ sudo apt install python3-pip

If your system uses the yum package manager, you can try the following:

$ sudo yum install python-pip

Pip is part of EPEL (Extra Packages for Enterprise Linux), so you might need to enable that first.

If these methods fail, you can also download a Python script that will install pip for you, with the following commands:

$ curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
$ python3 get-pip.py

Pip Install Python packages

Preferably, you install packages inside a virtual environment. Good news: pip is present inside your virtual environment by default. Because everything in our venv is installed locally, you don’t need to become a superuser with sudo or su.

Alternatively, you can install packages outside of a Python venv as well. This is only recommended for very generic packages, like pip itself. In fact, let’s try to upgrade our system-wide pip installation first. Make sure you are not currently in a virtual environment and enter:

sudo pip3 install --upgrade pip

This command asks pip to install pip, and update it if it’s already installed.

Now that we’re up-to-date, let’s try to install simplejson. Enter your virtual environment and type in:

$ pip install simplejson

Install packages using a requirements.txt file

In a virtual environment, it’s a good habit to install specific versions of packages. It ensures that you reap the full benefits of using virtual environments in the first place. After all, we do this to make sure our software always works as intended by pinning down specific dependency versions.

requirements.txt file contains a very simple list of dependencies, one per line. In its most simple form, it could look like this:


But what we really want is to pin the versions. That’s not hard either:


You can also relax these constraints a little, by using >= and <=, or even a combination of those:


How do you know what range to use? Unfortunately, there are no rules to this. You will have to read the release notes and such from the package in question.

Pip freeze

You can make your life a little easier by creating your requirements file using pip’s freeze option. First, write your software and install all the requirements you need as you go. Once you’re done, use the following command:

$ pip freeze > requirements.txt

Pip created a requirements.txt file with all the currently installed dependencies, including version numbers. Neat!

Pip Install from a requirements file

Finally, to install all the dependencies listed in this file, use:

$ pip install -r requirements.txt

Custom repository with pip install -i

The default PyPI repository is located at https://pypi.org/simple. You can use an alternative repository as well, though. For example, if your company only allows a subset of approved packages from an internal mirror. Or perhaps your company has a private mirror with their own package. This repository can be located on an HTTP(s) URL or on a file system location.

To specify a custom repository, use the -i or --index-url option, like so:

$ pip install -i https://your-custom-repo/simple <package name>


$ pip install -i /path/to/your/custom-repo/simple <package name>

The URL must point to a repository compliant with PEP 503 (the simple repository API) or a local directory laid out in the same format.

Install locally (no root or super user)

By default, pip tries to install a package system-wide. This can be fine, e.g. for generic libraries like Numpy and Pandas, or for complete environments like Jupyter Notebook. However, you won’t always have the super-user rights to install packages system-wide, e.g. when you’re working on a shared or locked down system at work or at school.

In such cases, you can install packages to the Python user install directory for your platform.
On Unix-like systems, this will typically be ~/.local/, and on Windows, it will be %APPDATA%\Python.

In fact, on Debian-based systems, installing packages in the local install directory is often the default when running outside of a virtual environment and not as root.

Here’s how you would install the requests package locally:

pip install --user requests

Editable install with pip install -e

Pip has the option to do an editable install, meaning you can install a package from a local source. But instead of copying the package files to some location on your system, pip creates symlinks to the codebase you’re installing it from. This way, you can work on the project and make changes and be able to directly test those changes without constantly reinstalling new versions of the package.

There are a number of reasons why you might need this option:

  • When you are creating your own package
  • If you want to fix someone else’s package
  • If you want to install a so-called bleeding edge version of package, right from its source repository

The editable install option is called with the -e option or --editable option. Let’s see what pip has to say about this option:

$ pip install --help

  -e, --editable Install a project in editable mode (i.e. setuptools "develop mode") from a local project path or a VCS url.

Typically, you will be working on a project using a version control system like git. While inside the root of the repository, you would install the project with:

pip install -e .

If you’re not in the project root, you can simply supply the path to the package source code instead of using the dot.

Pip uninstall

To uninstall a package with pip, we can use the ‘uninstall’ subcommand, e.g.:

pip uninstall <package name>

In line with the pip install command using a requirements file, you can also use such a file to uninstall packages:

pip uninstall -r requirements.txt

Get more information

We can also use pip to get more info about a package, or about the currently installed packages.

Listing installing packages with Pip

To list all the currently installed packages using pip, use the following command:

$ pip list

Package                 Version
----------------------- ---------------------
async-generator         1.10
attrs                   20.3.0
autopep8                1.5.7

It will show both package names and versions. When you run the command inside a virtual environment, only the packages of the venv are shown. If you run it outside of a venv, all the system-wide packages will be listed.

Show package details

Now that you know which packages are installed, you may need to inspect one in more detail. For this, we have the ‘show’ sub-command:

$ pip show attrs
Name: attrs
Version: 20.3.0
Summary: Classes Without Boilerplate
Home-page: https://www.attrs.org/
Author: Hynek Schlawack
Author-email: [email protected]
License: MIT
Location: /usr/lib/python3/dist-packages

It’s a quick way to look up what a package is and does, and who authored it.

Keep learning

About the author

Erik is the owner of Python Land and the author of many of the articles and tutorials on this website. He's been working as a professional software developer for 25 years, and he holds a Master of Science degree in computer science. His favorite language of choice: Python!