PIP Commands Cheatsheet — Essential Reference
pip is the standard package installer for Python. It allows you to install and manage additional packages that are not part of the Python standard library.
RECOMMENDED
Master PIP with Top Reference Books
Level up your DevOps skills. Find the best guide books and cheatsheet references for your engineering stack.
Commands
| Command | Description | Example |
|---|---|---|
pip install <package_name> |
Installs a Python package from PyPI (Python Package Index). | pip install requests |
pip install <package_name>==<version> |
Installs a specific version of a Python package. | pip install django==3.2.5 |
pip uninstall <package_name> |
Uninstalls a Python package. | pip uninstall requests |
pip list |
Lists all installed Python packages and their versions. | pip list |
pip show <package_name> |
Displays information about an installed package, including its version, location, and dependencies. | pip show requests |
pip freeze |
Outputs a list of installed packages in a format suitable for requirements files. | pip freeze > requirements.txt |
pip install -r <requirements_file> |
Installs all packages listed in a requirements file. | pip install -r requirements.txt |
pip install --upgrade <package_name> |
Upgrades an installed package to the latest available version. | pip install --upgrade requests |
Pro Tips
- Always use a virtual environment (venv or conda) to manage project-specific dependencies and avoid conflicts.
- Use `pip freeze > requirements.txt` to capture your project's dependencies for reproducibility.
- Regularly update pip itself using `python -m pip install --upgrade pip` to get the latest features and bug fixes.
Frequently Asked Questions
What is pip used for?
pip is used to install, upgrade, and manage Python packages from the Python Package Index (PyPI) or other package indexes. It helps in handling project dependencies efficiently.
How do I install pip?
pip is usually included with Python installations from version 3.4 onwards. If you need to install or upgrade it, you can use `python -m ensurepip --default-pip` or `python -m pip install --upgrade pip`.