pip: install Python packages

pip is the package installer for Python. It downloads packages from the Python Package Index, pypi.org, together with the packages they depend on. If you have used apt on Debian and Ubuntu or dnf on Rocky Linux, pip does the same for Python libraries. Its documentation is on pip.pypa.io.

Most outputs come from a fresh virtual environment with Python 3.12 and pip 25.0.1 in a container, checked on 26 October 2026; the older outputs say so where they appear.

Install pip

The Python installer from python.org for Windows and macOS includes pip; see Install Python on Windows. On Linux it is a separate package. Debian and Ubuntu:

sudo apt install python3-pip

Rocky Linux, RHEL and Fedora:

sudo dnf install python3-pip

Check it. This output is from Ubuntu 20.04:

pip3 --version

pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)

A Python without pip, for example one you built yourself, gets it from its own standard library:

python3 -m ensurepip --upgrade

Run pip as python -m pip

A computer often has several Pythons: the one of the system, one from python.org, one in each virtual environment. The commands pip and pip3 belong to whichever comes first in the PATH, which is not always the Python you run your code with. python -m pip always installs for the Python you call:

python -m pip --version

pip 25.0.1 from /root/.venv/lib/python3.12/site-packages/pip (python 3.12)

The line tells which pip it is, where it installs and for which Python. This page writes python -m pip everywhere; on systems where the command is python3 use python3 -m pip.

Work in a virtual environment

Do not install packages into the Python of the system: the system tools depend on its packages, and two projects soon need different versions of the same library. Give every project its own virtual environment:

python3 -m venv .venv

Activate it on Linux and macOS:

source .venv/bin/activate

On Windows:

.venv\Scripts\activate

A new environment has nothing but pip:

python -m pip list

Package Version ------- ------- pip 25.0.1

error: externally-managed-environment

Debian 12 and newer and Ubuntu 23.04 and newer protect the Python of the system. pip install outside a virtual environment stops with

error: externally-managed-environment

and an explanation. Ways out, best first:

Install packages

Install one package, for example Flask:

python -m pip install flask

pip installs what Flask depends on as well. The end of the output:

Installing collected packages: markupsafe, itsdangerous, click, blinker, werkzeug, jinja2, flask Successfully installed blinker-1.9.0 click-8.5.0 flask-3.1.3 itsdangerous-2.2.0 jinja2-3.1.6 markupsafe-3.0.4 werkzeug-3.1.9

Several packages at once, here Flask, requests and Django:

python -m pip install flask requests django

Package names are not case sensitive: Flask and flask are the same package. All commands: python -m pip help, one command: python -m pip help install.

Install a given version

An exact version:

python -m pip install flask==2.3.3

A range: Django older than 5. Put the requirement in double quotes, otherwise the shell takes < for a redirection; double quotes work in bash, the Command Prompt and PowerShell:

python -m pip install "Django<5"

Successfully installed Django-4.2.30 asgiref-3.13.0 sqlparse-0.6.0

pip took the newest 4.x version. "Django>=4.2,<5" sets both ends, "Django~=4.2" means 4.2 or newer but below 5.

Upgrade a package

-U or --upgrade installs the newest version over the old one:

python -m pip install -U flask

pip list

pip list shows the installed packages. -o (--outdated) shows those with a newer version on PyPI. After Flask 2.3.3 from the chapter above:

python -m pip list -o

Package Version Latest Type ------- ------- ------ ----- Flask 2.3.3 3.1.3 wheel pip 25.0.1 26.2.2 wheel

-u (--uptodate) shows the packages that are current.

pip show

pip show prints what pip knows about one package: the version, the license, where it is installed, what it needs and what needs it:

python -m pip show flask

Name: Flask Version: 3.1.3 Summary: A simple framework for building complex web applications. Home-page: Author: Author-email: License-Expression: BSD-3-Clause Location: /root/.venv/lib/python3.12/site-packages Requires: blinker, click, itsdangerous, jinja2, markupsafe, werkzeug Required-by:

Location answers the question which Python the package was installed for.

Uninstall

pip asks before it removes a package; -y answers yes:

python -m pip uninstall -y flask

Found existing installation: Flask 2.3.3 Uninstalling Flask-2.3.3: Successfully uninstalled Flask-2.3.3

The packages Flask brought along stay:

python -m pip list

Package Version ------------ ------- blinker 1.9.0 click 8.5.0 itsdangerous 2.2.0 Jinja2 3.1.6 MarkupSafe 3.0.4 pip 25.0.1 Werkzeug 3.1.9

Remove them by name, several in one command, or start a new virtual environment. pip check tells whether every installed package still has what it needs:

python -m pip check

No broken requirements found.

requirements.txt

pip freeze lists the installed packages with exact versions, in the format pip reads back. Save it in the project:

python -m pip freeze > requirements.txt

The file starts like this:

asgiref==3.13.0 blinker==1.9.0 click==8.5.0

On another computer, or in a new environment, install the same set:

python -m pip install -r requirements.txt

Packages that are already there at the right version are skipped:

Requirement already satisfied: sqlparse==0.6.0 in ./.venv/lib/python3.12/site-packages (from -r requirements.txt (line 8)) (0.6.0) Requirement already satisfied: Werkzeug==3.1.9 in ./.venv/lib/python3.12/site-packages (from -r requirements.txt (line 9)) (3.1.9)

Install from a folder

A package you downloaded or wrote yourself installs from its folder. The folder needs a pyproject.toml next to the code; here the code is hello/src/hello/__init__.py:

mkdir -p hello/src/hello

touch hello/src/hello/__init__.py

The smallest pyproject.toml names the package and its version:

vi hello/pyproject.toml

[project] name = "hello" version = "0.1.0"

Give pip the path. The ./ tells pip it is a folder, not a package name on PyPI:

python -m pip install ./hello

Successfully installed hello-0.1.0

This copies the code into the environment, so later changes in the folder are not seen until you install again. While you work on the package, install it in editable mode with -e instead: the environment then uses the folder itself.

python -m pip install -e ./hello

Successfully installed hello-0.1.0

Upgrade pip

pip tells you itself when it is old. Current versions print a notice after a command:

[notice] A new release of pip is available: 24.0 -> 26.2.2 [notice] To update, run: pip install --upgrade pip

Older versions printed a warning; this one is from pip 19.2.3:

WARNING: You are using pip version 19.2.3, however version 20.1.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

Upgrade through Python. On Windows this is the only way: pip.exe cannot replace itself while it runs.

python -m pip install --upgrade pip

Uninstalling pip-24.0: Successfully uninstalled pip-24.0 Successfully installed pip-26.2.2

Inside a virtual environment this upgrades the pip of that environment only.

WARNING: pip is being invoked by an old script wrapper

The pip command is a small script. When it was created by an older pip or by the distribution, and pip itself was upgraded since, the script calls pip in a way the new version no longer supports, and pip warns. This output is from Python 3.6:

pip -V

WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
pip 20.3.3 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)

As the warning says, call pip through Python:

python -m pip -V

pip 20.3.3 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)

pip for a given Python version

With several Python versions on Linux or macOS, call the one you want by its version:

python3.12 -m pip install flask

On Windows the Python launcher py picks the version:

py -3.12 -m pip install flask

Without a virtual environment and without root rights, for example on a shared hosting, --user installs into your home folder. --ignore-installed installs the package there even when the system Python already has some version of it:

python3.12 -m pip install --user --ignore-installed flask

Article authors: Andrei Olegovich, Klavdiya Kondakova