Home·Terminal commands

pip install

Packages and runtimes

Usage

python -m pip install [-r requirements.txt] <package>

Installs a package into whichever Python is active; calling it as python -m pip avoids the classic case of pip belonging to another interpreter, and since PEP 668 a system Python refuses installs outside a virtual environment.

Common flags

FlagMeaning
-r <file>install everything a requirements file lists
-Uupgrade to the newest allowed version
-e .editable install of the project you are in
--userinto your home directory instead of the system
--no-depsthis package only, no dependencies
-c <file>apply a constraints file to the versions
--break-system-packagesoverride the PEP 668 refusal on a system python

Examples

python -m pip install -r requirements.txt

installs a pinned set into the active environment

python -m pip install -U requests

upgrades one package

python -m pip install -e .

installs your own project so edits take effect at once

The question is always what goes where: inside this project, or on the whole machine.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does pip install do?

Installs a package into whichever Python is active; calling it as python -m pip avoids the classic case of pip belonging to another interpreter, and since PEP 668 a system Python refuses installs outside a virtual environment.

Q. How do I type it?

python -m pip install [-r requirements.txt] <package> — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

7 are listed here; the full set is in man pip. This command sits under Packages and runtimes.

Related commands

man page: man pip-install