pip — The Python Package Installer

Practical guide to pip — install, manage and pin Python packages from PyPI, using requirements.txt and isolated venv environments.

pip is the standard installer for Python packages, pulling them by default from the Python Package Index (PyPI). With it you install, upgrade and remove libraries, pin your dependencies in a requirements.txt, and rebuild an environment reproducibly whenever you need to. The recommended way to invoke it is python -m pip, which makes it unambiguous which interpreter you mean – especially handy when several Python versions are installed. This guide walks you through the commands you reach for daily, from a single package to a complete virtual environment.

Install Packages

pip install <package> — Install a package from PyPI.

pip install requests

pip install <package>==<version> — Install a specific version.

pip install django==5.0.2

pip install '<package>>=<min>,<<max>' — Install with version constraints.

pip install 'flask>=3.0,<4.0'

pip install -r requirements.txt — Install all packages from a requirements file.

pip install -r requirements.txt

pip install -e . — Install current project in editable/development mode.

pip install -e .

pip install <package> --user — Install to user directory (no sudo needed).

pip install httpie --user

pip install <url> — Install from a Git repository URL.

pip install git+https://github.com/user/repo.git@main

Uninstall & Manage

pip uninstall <package> — Remove an installed package.

pip uninstall requests

pip uninstall -y <package> — Remove without confirmation prompt.

pip uninstall -y flask

pip install --upgrade <package> — Upgrade a package to the latest version.

pip install --upgrade pip

pip install --upgrade -r requirements.txt — Upgrade all packages from requirements file.

pip install --upgrade -r requirements.txt

pip install --force-reinstall <package> — Force reinstall even if already installed.

pip install --force-reinstall numpy

List & Info

pip list — List all installed packages.

pip list

pip list --outdated — Show packages with newer versions available.

pip list --outdated

pip show <package> — Show detailed info about an installed package.

pip show django

pip show -f <package> — Show package info including installed files.

pip show -f requests

pip search <query> — Search PyPI for packages (may be disabled on PyPI).

pip search 'web framework'

Freeze & Requirements

pip freeze — Output installed packages in requirements.txt format.

pip freeze

pip freeze > requirements.txt — Save current packages to requirements file.

pip freeze > requirements.txt

pip freeze --exclude <package> — Freeze but exclude specific packages.

pip freeze --exclude pip --exclude setuptools

pip install -c constraints.txt — Install with version constraints from a file.

pip install -r requirements.txt -c constraints.txt

Virtual Environments

python -m venv <dir> — Create a new virtual environment.

python -m venv .venv

source <dir>/bin/activate — Activate a virtual environment (Linux/macOS).

source .venv/bin/activate

deactivate — Deactivate the current virtual environment.

deactivate

pip install --target <dir> <package> — Install packages to a specific directory.

pip install --target ./libs requests

Download & Cache

pip download <package> — Download packages without installing.

pip download -d ./packages requests

pip cache info — Show pip cache information.

pip cache info

pip cache purge — Clear the pip cache.

pip cache purge

pip install --no-cache-dir <package> — Install without using or storing cache.

pip install --no-cache-dir tensorflow

Conclusion

pip is the foundation of the Python ecosystem: with a handful of commands you install packages, keep them current, and make your environment reproducible through requirements.txt. Avoid installing into the system Python – on modern distributions PEP 668 blocks that anyway – and work inside a virtual environment (python -m venv) or, if you must, with --user. Install only trusted PyPI packages: a typo in a package name can land you on a typosquatting package carrying malicious code. Pin your versions in requirements.txt and rebuild the environment reproducibly with pip install -r.

Further Reading

  • apk – package manager of the Alpine Linux distribution
  • apt – high-level package manager for Debian and Ubuntu
  • apt-get – classic package management tool for Debian and Ubuntu