# pip — The Python Package Installer

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

Source: https://www.jpkc.com/db/en/cheatsheets/package-managers/pip/

<!-- PROSE:intro -->
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.
<!-- PROSE:intro:end -->

## Install Packages

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

```bash
pip install requests
```

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

```bash
pip install django==5.0.2
```

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

```bash
pip install 'flask>=3.0,<4.0'
```

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

```bash
pip install -r requirements.txt
```

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

```bash
pip install -e .
```

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

```bash
pip install httpie --user
```

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

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

## Uninstall & Manage

`pip uninstall <package>` — Remove an installed package.

```bash
pip uninstall requests
```

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

```bash
pip uninstall -y flask
```

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

```bash
pip install --upgrade pip
```

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

```bash
pip install --upgrade -r requirements.txt
```

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

```bash
pip install --force-reinstall numpy
```

## List & Info

`pip list` — List all installed packages.

```bash
pip list
```

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

```bash
pip list --outdated
```

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

```bash
pip show django
```

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

```bash
pip show -f requests
```

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

```bash
pip search 'web framework'
```

## Freeze & Requirements

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

```bash
pip freeze
```

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

```bash
pip freeze > requirements.txt
```

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

```bash
pip freeze --exclude pip --exclude setuptools
```

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

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

## Virtual Environments

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

```bash
python -m venv .venv
```

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

```bash
source .venv/bin/activate
```

`deactivate` — Deactivate the current virtual environment.

```bash
deactivate
```

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

```bash
pip install --target ./libs requests
```

## Download & Cache

`pip download <package>` — Download packages without installing.

```bash
pip download -d ./packages requests
```

`pip cache info` — Show pip cache information.

```bash
pip cache info
```

`pip cache purge` — Clear the pip cache.

```bash
pip cache purge
```

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

```bash
pip install --no-cache-dir tensorflow
```

<!-- PROSE:outro -->
## 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](https://pip.pypa.io/) – official reference for commands, options and configuration
- [Python Packaging User Guide](https://packaging.python.org/) – official guide to packaging, virtual environments and best practices
- [PyPI](https://pypi.org/) – the central index pip installs from by default
<!-- PROSE:outro:end -->

## Related Commands

- [apk](https://www.jpkc.com/db/en/cheatsheets/package-managers/apk/) – package manager of the Alpine Linux distribution
- [apt](https://www.jpkc.com/db/en/cheatsheets/package-managers/apt/) – high-level package manager for Debian and Ubuntu
- [apt-get](https://www.jpkc.com/db/en/cheatsheets/package-managers/apt-get/) – classic package management tool for Debian and Ubuntu

