Install and Manage Python Packages

Use pip to install third-party Python packages, check installed versions, upgrade, and remove packages.

6 min read

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:

bashbash
python -m pip --version

Or on systems where Python 3 uses the python3 command:

bashbash
python3 -m pip --version

You should see output like:

plaintextplaintext
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:

bashbash
python -m ensurepip --default-pip

For 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:

bashbash
python -m pip install requests

requests is a popular library for making HTTP requests. When you run this command, pip:

  1. Searches PyPI for a package named requests.
  2. Downloads the latest version that works with your Python version.
  3. Installs it into your Python environment.

After installation, you can use the package in any Python script:

pythonpython
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:

bashbash
python -m pip install requests==2.31.0

You can also specify version ranges:

bashbash
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:

bashbash
python -m pip list

Output looks like:

plaintextplaintext
Package    Version
---------- ---------
pip        26.1.2
requests   2.32.4
...

For details about a specific package:

bashbash
python -m pip show requests

This 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:

bashbash
python -m pip install --upgrade requests

You can also upgrade pip itself:

bashbash
python -m pip install --upgrade pip

Keep 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:

bashbash
python -m pip uninstall requests

pip 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:

bashbash
python -m pip freeze > requirements.txt

This saves all installed packages and their exact versions:

plaintextplaintext
requests==2.32.4

Later, you or someone else can install everything with:

bashbash
python -m pip install -r requirements.txt

Commit 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:

bashbash
python -m pip install --user requests

This 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:

PackagePurpose
requestsHTTP requests for APIs and web pages
richColored terminal output and tables
pillowImage processing and manipulation
pandasData analysis with tables and spreadsheets
flaskLightweight 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

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.

RunePowered by Rune AI

Frequently Asked Questions

What is pip?

pip is the standard package installer for Python. It downloads and installs packages from the Python Package Index (PyPI). pip comes included with Python 3.4 and later.

What is the difference between pip install and pip install --user?

pip install installs globally (may need admin access). pip install --user installs only for your user account and does not require special permissions. Inside a virtual environment, both behave the same and affect only that environment.

How do I know which packages are installed?

Run pip list to see all installed packages with versions, or pip show package-name for details on a specific package.

Can I install multiple packages at once?

Yes. Run pip install package1 package2 package3, or list them in a requirements.txt file and run pip install -r requirements.txt.

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.