Install a package

pip install requests

This fetches the latest version from the Python Package Index (PyPI) and makes it available to import.

Install a specific version

pip install requests==2.31.0

Pinning a version with == keeps your project reproducible and avoids surprise upgrades.

Install everything in a requirements file

pip install -r requirements.txt

A requirements.txt lists one package per line, so a whole project sets up with a single command.

Upgrade or remove a package

pip install --upgrade requests
pip uninstall requests

Use --upgrade to move to the newest version, and uninstall to remove one cleanly.

Common mistakes

  • Installing globally instead of in a virtual environment. Activate a venv first so projects stay isolated.
  • Using pip when you have several Pythons. Prefer python -m pip so the package lands in the right interpreter.

Frequently asked questions

What is the difference between pip and python -m pip?

They usually do the same thing, but python -m pip guarantees you use the pip that belongs to that exact Python, which avoids installing into the wrong version.

Where do pip packages get installed?

Into your active environment’s site-packages folder. Inside a virtual environment, that keeps each project’s dependencies separate.

Ready to build real projects with these libraries? Start with our free Python course.