Python comes with a rich standard library, but much of Python's power comes from third-party packages. These are libraries written by other developers that you can install and use in your own programs. The tool for installing them is called pip.
Before reading this article, make sure you have written and run a Python script and understand how Python runs your code.
Check that pip is available
Open a terminal and run:
python -m pip --versionOr on systems where Python 3 uses the python3 command:
python3 -m pip --versionYou should see output like:
pip 26.1.2 from /usr/local/lib/python3.14/site-packages/pip (python 3.14)If you see a version number, pip is ready. If the command is not found, pip may not be installed. Try bootstrapping it:
python -m ensurepip --default-pipFor a full walkthrough, see the fix common Python installation errors guide.
Always run pip as python -m pip rather than just pip. The -m flag tells Python to run the pip module directly, which guarantees you are using the pip that belongs to the Python interpreter you intend. Using bare pip can accidentally point to a different Python installation.
Install a package
The Python Package Index (PyPI) at pypi.org hosts hundreds of thousands of packages. To install one, use:
python -m pip install requestsrequests is a popular library for making HTTP requests. When you run this command, pip:
- Searches PyPI for a package named
requests. - Downloads the latest version that works with your Python version.
- Installs it into your Python environment.
After installation, you can use the package in any Python script:
import requests
response = requests.get("https://api.github.com")
print(response.status_code)A ModuleNotFoundError means the package is not installed, or you installed it in a different Python environment than the one running your script. If you are using virtual environments, make sure the environment is activated.
Install a specific version
Sometimes you need a particular version of a package. Use == to pin the version:
python -m pip install requests==2.31.0You can also specify version ranges:
python -m pip install "requests>=2.28,<3.0"This installs any version 2.28 or higher but below 3.0. Version pinning becomes important when you start creating projects with multiple dependencies.
List installed packages
To see everything installed in your current Python environment:
python -m pip listOutput looks like:
Package Version
---------- ---------
pip 26.1.2
requests 2.32.4
...For details about a specific package:
python -m pip show requestsThis prints the version, author, license, dependencies, and install location.
Upgrade a package
Packages receive updates with bug fixes and new features. To upgrade to the latest version:
python -m pip install --upgrade requestsYou can also upgrade pip itself:
python -m pip install --upgrade pipKeep pip current. Older versions may not work with the latest packages or Python releases.
Uninstall a package
To remove a package you no longer need:
python -m pip uninstall requestspip asks for confirmation before removing the package. Type y and press Enter to proceed.
Be careful: pip does not automatically remove dependencies that were installed alongside the package. If package A depends on package B, uninstalling A leaves B behind. Over time, this can leave unused packages in your environment. Using virtual environments helps because you can delete the entire environment when you no longer need it.
Requirements files
When you work on a project, you want to track which packages it needs so others can set up the same environment. The standard way is a requirements.txt file.
Generate one from your current environment:
python -m pip freeze > requirements.txtThis saves all installed packages and their exact versions:
requests==2.32.4Later, you or someone else can install everything with:
python -m pip install -r requirements.txtCommit requirements.txt to version control alongside your code. It lets anyone clone your project and install the exact same dependencies.
For a more structured project setup, including where to place requirements.txt, see create your first Python project.
Install packages for your user only
If you are not using a virtual environment and you get a permission error, install packages for your user account only:
python -m pip install --user requestsThis installs packages into a user-specific directory instead of the system-wide Python installation. The --user flag has no effect inside an active virtual environment because virtual environments are already isolated.
Find packages on PyPI
Not sure which package to use? Search on pypi.org directly. The PyPI website lets you browse packages by name, category, and popularity. Pip's old pip search command no longer works because the PyPI search API was disabled.
For beginners, a few widely-used packages to explore:
| Package | Purpose |
|---|---|
requests | HTTP requests for APIs and web pages |
rich | Colored terminal output and tables |
pillow | Image processing and manipulation |
pandas | Data analysis with tables and spreadsheets |
flask | Lightweight web applications |
Install one, read its documentation, and try it in a small script. Hands-on experimentation is the best way to learn what packages can do.
Next steps
Package management makes more sense when you pair it with virtual environments, which keep each project's packages isolated. After that, learn how to structure your first Python project with a clean layout and a requirements.txt file.
Rune AI
Key Insights
Use python -m pip install package-name to add a library; Check installed packages with pip list and pip show; Upgrade with --upgrade and uninstall with pip uninstall; Use requirements.txt to share a project's package list.
Frequently Asked Questions
What is pip?
What is the difference between pip install and pip install --user?
How do I know which packages are installed?
Can I install multiple packages at once?
Conclusion
pip is your gateway to the Python ecosystem. Once you can install, list, upgrade, and remove packages, you can use thousands of libraries in your programs.
More in this topic
Create and Assign Variables in Python
Learn every way to create and assign variables in Python, from basic single assignment to expressions, type hints, and practical patterns beginners use every day.
Python Variable Naming Rules
Learn Python's variable naming rules, including allowed characters, reserved keywords, PEP 8 conventions, and how to choose names that make your code readable.
Python Variables Explained
Understand what Python variables are, how they store and reference data, and why Python's variable model is different from other programming languages.