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 with pip:
- Manual installation
- Using a
requirements.txtfile that defines the required packages and their version numbers.
How to use pip: the commands you need
Here are the pip commands you’ll use most, with requests as the example package. Run them inside an activated virtual environment. On macOS and Linux, type python3 instead of python if the first doesn’t work.
| Command | What it does |
|---|---|
python -m pip install requests | Install a package (latest version) |
python -m pip install "requests==2.32.3" | Install one specific version |
python -m pip install --upgrade requests | Upgrade a package to the latest version |
python -m pip install -r requirements.txt | Install everything in a requirements file |
python -m pip freeze > requirements.txt | Save the exact versions you have installed |
python -m pip uninstall requests | Remove a package |
python -m pip list | List installed packages |
python -m pip show requests | Show details of one package |
python -m pip install --upgrade pip | Upgrade pip itself |
Did pip just refuse to install anything with error: externally-managed-environment? Then jump straight to what that error means and how to fix it. Otherwise, let’s make sure pip itself is installed first!
How to install pip
First things first: we need to install pip itself. The good news is that Pip is probably already present in your system. Every current Python downloaded from python.org includes pip, and so does every virtual environment you create.
So before you try to install Pip, ensure it’s not already on your system. Open a terminal (Linux/MacOS) or a Windows shell, and type in the following command:
python -m pip --versionCode language: plaintext (plaintext)
On macOS and Linux, the Python command is often called python3, so try python3 -m pip --version if the first one fails. You should see something like this:
pip 26.2.2 from /home/erik/projects/myproject/.venv/lib/python3.15/site-packages/pip (python 3.15)Code language: plaintext (plaintext)
I use python -m pip instead of plain pip throughout this article, and I recommend you do the same. It runs the pip that belongs to the exact Python you name, so packages always end up where that Python can find them. Plain pip (or pip3) usually works too, but on a system with several Pythons, it’s easy to install a package for the wrong one.
If that failed, you need to install pip yourself, so let’s take a look at how to do so manually. You should do this only as a last resort, and I strongly suggest you first check if your Python installation went well.
Install Pip on Windows and Mac
On Windows and Mac, first try the ensurepip module that ships with Python:
python -m ensurepip --upgradeCode language: plaintext (plaintext)
If that doesn’t work either, 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, in the directory where you saved it:
python get-pip.pyCode language: plaintext (plaintext)
Install Pip on Linux (Ubuntu, Debian, Fedora)
On Linux, install pip with your distribution’s package manager. This is the most recommended method and ensures your system stays consistent. On Debian, Ubuntu, Linux Mint, and other Debian derivatives, use apt. The python3-venv package gives you virtual environments, which you’ll want as well:
$ sudo apt install python3-pip python3-venvCode language: Bash (bash)
On Fedora, Red Hat, and similar systems, use dnf:
$ sudo dnf install python3-pipCode language: Bash (bash)
Don’t run get-pip.py on your Linux system’s Python. Most distributions mark their Python as externally managed, and you’d be working against the package manager. Use pip inside a virtual environment instead, as explained below.
Pip Install Python packages
I can’t stress this enough: install packages inside a virtual environment. And the 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 and you don’t risk package version conflicts.
The one exception is command-line tools you want to use everywhere, like IPython, Jupyter Notebook, or the code formatter black. For those, use pipx, which gives every tool its own virtual environment behind the scenes.
Install Python packages in a venv
Now let’s try to install a package inside a virtual environment. For this example, I picked requests, a popular package for talking to websites and APIs. First, create and activate your virtual environment, and then type:
(.venv) $ python -m pip install requests
...
Successfully installed certifi-2026.10.23 charset-normalizer-3.5.2 idna-3.20 requests-2.34.2 urllib3-2.8.0Code language: plaintext (plaintext)
You just installed a package inside of your virtual environment, and as such it will only be accessible when you activate this venv. Notice that pip installed four more packages: requests needs them to do its job, so pip installs them automatically. We call these dependencies.
Want to see how pip fits into a real project? Follow our free lesson on installing a package inside a virtual environment. The lesson builds on the virtual environment created in the preceding lesson.
While you’re in the venv, you can also upgrade pip itself. Pip may even suggest it with a notice at the end of an install:
(.venv) $ python -m pip install --upgrade pip
...
Successfully installed pip-26.3Code language: plaintext (plaintext)
error: externally-managed-environment
If you run pip install outside a virtual environment on Ubuntu, Debian, Fedora, or with Homebrew’s Python on macOS, you’ll likely get this instead of a package. This is the output on Ubuntu 26.04:
$ python3 -m pip install requests
error: externally-managed-environment
× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
python3-xyz, where xyz is the package you are trying to
install.
If you wish to install a non-Debian-packaged Python package,
create a virtual environment using python3 -m venv path/to/venv.
Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
sure you have python3-full installed.
If you wish to install a non-Debian packaged Python application,
it may be easiest to use pipx install xyz, which will manage a
virtual environment for you. Make sure you have pipx installed.
See /usr/share/doc/python3.14/README.venv for more information.
note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.Code language: plaintext (plaintext)
Homebrew prints the same error with brew install in place of apt install. Adding --user doesn’t help; you get the same message.
Why pip refuses
On these systems, the Python in /usr/bin (or Homebrew’s) isn’t just yours. Parts of the operating system are written in Python and depend on the packages the system’s package manager installed. If pip replaces one of those with a different version, apt or brew doesn’t know about it, and system tools can break in confusing ways. Since PEP 668, a distribution can put a marker file named EXTERNALLY-MANAGED next to its Python, and pip respects it by refusing to install outside a virtual environment.
How to fix it
The error message lists the right answers. Which one you need depends on what you’re installing:
- A library for your own code or project: create a virtual environment and install it there. This is the answer most of the time:
python3 -m venv .venvsource .venv/bin/activatepython -m pip install requests - A command-line tool you want available everywhere (black, httpie, Jupyter, and so on): use pipx. Install pipx itself with
sudo apt install pipxorbrew install pipx. - A package that a system program needs: install the distribution’s version, like
sudo apt install python3-requests. These are often older than the latest release on PyPI, but they’re tested with your system.
You’ll find plenty of advice online to add --break-system-packages, or to delete the EXTERNALLY-MANAGED file. Both make the error go away by turning off the protection, and both can break your system’s Python on the next OS update. A venv takes one command to create and solves the problem properly.
Pip has more error messages that look scary but tell you exactly what’s wrong once you know how to read them. The free lesson Read a package failure shows two common ones and what to do about each.
Install locally (no root or superuser)
Before virtual environments became the norm, the way to install packages without administrator rights was pip’s --user option. It installs packages to the Python user install directory for your platform, typically:
~/.local/on Unix-like systems.%APPDATA%\Pythonon Windows
It still works with Python from python.org on Windows and macOS, but on externally managed systems it’s refused just like a system-wide install. And user installs share the same problem as system-wide ones: every project sees the same versions. Use a virtual environment for libraries and pipx for tools, and you won’t need --user at all.
Consider pipx
If you need to install packages system-wide, it’s often because they are some kind of tool that you use often (like Poetry, black, Jupyter Notebook) instead of a dependency that your project needs. If this is the case, pipx is the ideal tool to use. It creates a separate virtual environment for each tool and makes its commands available on your PATH:
$ pipx install black
installed package black 26.10.1, installed using Python 3.15.2
These apps are now available
- black
- blackd
done! ✨ 🌟 ✨Code language: plaintext (plaintext)
Install Python packages system-wide
Let me first repeat that I don’t recommend this. If you jumped in here without reading the rest of the topic, please read the sections above about virtual environments and pipx first.
On Linux, sudo pip install used to be the way to do this. On current distributions it fails with the externally-managed-environment error, and that’s a good thing. If something really must be installed for the whole system, use the package manager: sudo apt install python3-xyz or sudo dnf install python3-xyz.
An alternative: uv pip install
uv is a newer tool that does the same job as venv and pip, but much faster. Its commands mirror pip’s: uv venv creates a .venv directory, and uv pip install requests installs into it, without activating it first. Everything in this article about versions and requirements files applies to uv as well. Learn pip first, though: uv makes a lot more sense once you know what it does for you. Our uv tutorial picks up where this article ends.
Pip install requirements.txt file
In a virtual environment, installing specific versions of packages is a good habit. It ensures that you reap the full benefits of using virtual environments in the first place. After all, we do this to ensure our software always works as intended by pinning down specific dependency versions.
A requirements.txt file contains a simple list of dependencies, one per line. In its most simple form, it could look like this:
requests
richCode language: plaintext (plaintext)
But what we really want is to pin the versions. That’s not hard either:
requests==2.34.2
rich==15.0.0Code language: plaintext (plaintext)
You can also relax these constraints a little, by using >= and <, or even a combination of those:
requests>=2.32,<3
rich>=13Code language: plaintext (plaintext)
You can use any of these specifiers: ==, !=, >, >=, <, <=, and ~=. That last one is called the compatible release operator: requests~=2.32 means “2.32 or newer, but still 2.x”. It’s a short way to write requests>=2.32,<3.
Writing down what a project needs, and rebuilding the venv from that file, is exactly what the free lesson Write down what the project needs lets you practice.
What version range to pick
How do you know what range to use? Most tutorials and courses seem to avoid this topic. Unfortunately, there are no hard rules. You will have to read the release notes and such from the package(s) in question.
For example, let’s assume you are using two packages, A and B. Perhaps you know that a certain feature became available in package A, version 3.1.0, so you require at least that version. But from the news, you learned that the author is planning a major overhaul of package A’s API in version 4.0.0. In addition, package B is a bit stale and poorly maintained. It’s been stuck at version 0.6.2 for ages and requires package A version 3.1.6 or lower (while A is currently at 3.5.0). You could define the following constraints to ensure everything works together nicely:
A>=3.1.0,<=3.1.6
B==0.6.2Code language: plaintext (plaintext)
Without package B, a sensible choice for A would be A~=3.1: at least 3.1, and no 4.0 until you’ve had a chance to test it.
You see, it requires some juggling sometimes to define version constraints properly. That’s why many developers use a tool that resolves and locks all the dependencies for them, like uv or Poetry. Right now, we’re making sure you understand the basics. This way, those tools will seem less magical, and you’ll better understand what they do for you.
Pip freeze
Creating your requirements file using pip’s freeze option can make your life a little easier. First, write your software and install all the requirements you need as you go. Once you’re done and everything seems to work fine, use the following command:
(.venv) $ python -m pip freeze > requirements.txtCode language: Bash (bash)
Pip created a requirements.txt file with all the currently installed packages, including version numbers. Neat! After installing only requests, it looks like this:
certifi==2026.10.23
charset-normalizer==3.5.2
idna==3.20
requests==2.34.2
urllib3==2.8.0Code language: plaintext (plaintext)
As you can see, freeze lists the dependencies of your dependencies too. Some people like that because it records exactly what worked; others prefer to write a short file by hand with only the packages they import. You may also choose to relax the versions a little, e.g. to allow for minor updates (bug fixes, security fixes) to a package. But remember that it’s a risk too: there’s always a chance of ending up with a project that doesn’t work as intended because one of the requirements changed the behavior of its API or something.
Pip Install from a requirements.txt file
Finally, to install all the dependencies listed in this file, use:
(.venv) $ python -m pip install -r requirements.txtCode language: Bash (bash)
It’s an instruction that you’ll often see when reading the installation instructions for Python projects, and now you know exactly what it does and how it works!
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:
python -m pip install -i https://your-custom-repo/simple <package-name>
or
python -m pip install -i /path/to/your/custom-repo/simple <package-name>Code language: plaintext (plaintext)
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.
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 points Python at the source code 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 a 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:
$ python -m pip install --help
..
-e, --editable <path/url> Install a project in editable mode (i.e.
setuptools "develop mode") from a local project
path or a VCS url.
..Code language: plaintext (plaintext)
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:
python -m pip install -e .Code language: plaintext (plaintext)
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. to uninstall requests:
(.venv) $ python -m pip uninstall requests
Found existing installation: requests 2.34.2
Uninstalling requests-2.34.2:
Would remove:
/home/erik/projects/myproject/.venv/lib/python3.15/site-packages/requests-2.34.2.dist-info/*
/home/erik/projects/myproject/.venv/lib/python3.15/site-packages/requests/*
Proceed (Y/n)? y
Successfully uninstalled requests-2.34.2Code language: plaintext (plaintext)
Add -y to skip the question. Note that pip only removes the package you name, not the dependencies it installed along with it. In line with the pip install command using a requirements file, you can also use such a file to uninstall packages:
python -m pip uninstall -r requirements.txtCode language: plaintext (plaintext)
Inside a venv, there’s an even simpler way to clean up everything: delete the venv directory and create a new one.
More pip commands
We can also use pip to get more info about a package or the currently installed packages. Let’s explore these additional commands.
Pip list: listing installed packages
To list all the currently installed packages using pip, use the following command:
(.venv) $ python -m pip list
Package Version
------------------ ----------
certifi 2026.10.23
charset-normalizer 3.5.2
idna 3.20
pip 26.3
requests 2.34.2
urllib3 2.8.0Code language: plaintext (plaintext)
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. All account-wide or system-wide packages will be listed if you run it outside of a venv.
Pip show: get 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:
(.venv) $ python -m pip show requests
Name: requests
Version: 2.34.2
Summary: Python HTTP for Humans.
Home-page:
Author:
Author-email: Kenneth Reitz <me@kennethreitz.org>
License: Apache-2.0
Location: /home/erik/projects/myproject/.venv/lib/python3.15/site-packages
Requires: certifi, charset_normalizer, idna, urllib3
Required-by: Code language: plaintext (plaintext)
It’s a quick way to determine what a package is and does, who authored it, and which other packages it needs. The Location line is also handy when you’re not sure which Python a package was installed for.
The Python Package Index
We haven’t talked extensively about the Python Package index yet, which is located at pypi.org. The site offers us a few things:
- You can create an account, which you need only when you want to publish your own packages
- It offers a search function (more on this further on)
- It shows us use stats, like the total amount of packages and user
- We can browse by category
To be honest, the Python package index is somewhat lacking, and I don’t think many people use the site beyond reading some package information.
PyPI search function
You may have seen pip search in older tutorials. It doesn’t work anymore: PyPI switched off the search API that it used, because it put too much load on their servers. If you try it, pip ends with this error:
RuntimeError: PyPI no longer supports 'pip search' (or XML-RPC search). Please use https://pypi.org/search (via a browser) instead.Code language: plaintext (plaintext)
So the search on the website is what’s left. If you know exactly what you are looking for, it’s okay. For example, let’s try a search for the immensely popular requests package. It will show up first, and we can click through to the information page here where we can see things like:
- A description of the package
- The author’s name and email address
- links to the project’s homepage, documentation, and source code
- A list of historic releases
The package authors provide all this info, so keep that in mind.
Now suppose we can’t remember the name requests, and we search for the word HTTP instead:

You can try and see for yourself if you want: the requests package is nowhere to be found. So if you need to discover a library to do a specific thing, like making HTTP requests, I strongly suggest you use a search engine instead.
A simple search will yield that Python has a built-in HTTP library, which might be good enough. However, several of the first results also mention requests, giving us a strong indicator that this package is used a lot.
PyPI Categories
If you browse the categories instead, you’ll also find that they aren’t very helpful. Luckily, the Python community is strong, and many sites (like Python Land!) fill in the gaps and offer good advice on which packages to use.
So, in short: the PyPI site won’t be very useful for discovery. Still, it will be more than adequate to give you package information and links to documentation and source repositories.
Be careful what you install
It is crucial to realize that anyone can upload packages to PyPI. This includes bad actors. Unfortunately, this is not a hypothetical issue. There have been several examples of malicious packages masquerading as known projects. E.g., someone might upload a package called requests2. There are many tricks you and I wouldn’t think of to deceive people. So this raises the question: how do you know which packages to trust and which to avoid?
How to know which packages are trustworthy
I’ll outline a few steps you can take to significantly reduce the risk of installing a malicious package.
- Do a web search for the package name. Well-known packages like
requestsare mentioned a lot in articles, tutorials, etcetera. - Visit not just the PyPI page but also the accompanying source code page (most often, that will be Github).
- Look up the package on libraries.io. They show a few interesting metrics per package, one of which is called ‘Dependent packages.’ This number shows how many other packages use this package, giving you a strong indication of its popularity and trustworthiness.
- Finally, when installing the package, double-check the name before hitting enter to avoid typo squatters.
Keep learning
This article is part of a free Python Tutorial. You can browse the tutorial with the navigation buttons at the top and bottom of the article or use the navigation menu. Here are some other articles and links you may want to check out:
- Check out my virtual environments tutorial, if you haven’t already done so.
- If you want a tool that also manages and locks your dependencies, look at uv or Poetry.
- If you want to learn more about pip and all its options, visit the official pip documentation.
- Read about pip’s configuration files
- The pip documentation on editable installs and other local project installs
- PEP 668, the specification behind the externally-managed-environment error