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 requestspip install <package>==<version> — Install a specific version.
pip install django==5.0.2pip 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.txtpip 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 --userpip install <url> — Install from a Git repository URL.
pip install git+https://github.com/user/repo.git@mainUninstall & Manage
pip uninstall <package> — Remove an installed package.
pip uninstall requestspip uninstall -y <package> — Remove without confirmation prompt.
pip uninstall -y flaskpip install --upgrade <package> — Upgrade a package to the latest version.
pip install --upgrade pippip install --upgrade -r requirements.txt — Upgrade all packages from requirements file.
pip install --upgrade -r requirements.txtpip install --force-reinstall <package> — Force reinstall even if already installed.
pip install --force-reinstall numpyList & Info
pip list — List all installed packages.
pip listpip list --outdated — Show packages with newer versions available.
pip list --outdatedpip show <package> — Show detailed info about an installed package.
pip show djangopip show -f <package> — Show package info including installed files.
pip show -f requestspip 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 freezepip freeze > requirements.txt — Save current packages to requirements file.
pip freeze > requirements.txtpip freeze --exclude <package> — Freeze but exclude specific packages.
pip freeze --exclude pip --exclude setuptoolspip install -c constraints.txt — Install with version constraints from a file.
pip install -r requirements.txt -c constraints.txtVirtual Environments
python -m venv <dir> — Create a new virtual environment.
python -m venv .venvsource <dir>/bin/activate — Activate a virtual environment (Linux/macOS).
source .venv/bin/activatedeactivate — Deactivate the current virtual environment.
deactivatepip install --target <dir> <package> — Install packages to a specific directory.
pip install --target ./libs requestsDownload & Cache
pip download <package> — Download packages without installing.
pip download -d ./packages requestspip cache info — Show pip cache information.
pip cache infopip cache purge — Clear the pip cache.
pip cache purgepip 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
- pip documentation – official reference for commands, options and configuration
- Python Packaging User Guide – official guide to packaging, virtual environments and best practices
- PyPI – the central index pip installs from by default