Menu
Try in Playground

Python pip: Install Packages, Manage Versions, and Use PyPI

How to install, upgrade, and remove Python packages with pip — including PyPI, requirements files, and avoiding the global-install trap.

What pip Actually Is

pip is the tool that installs Python libraries you didn't write yourself. When you run pip install requests, it looks up requests on PyPI (the Python Package Index), downloads the right version for your platform, and drops it into the site-packages directory of your Python install. After that, import requests works.

Every Python 3 install from python.org, Homebrew, or your Linux package manager comes with pip already. Before you install anything, verify:

python -m pip --version

You should see a version number and a path to the pip module. If the command fails, the most reliable fix is:

python -m ensurepip --upgrade

That bootstraps pip into your Python install using the copy that ships with the interpreter.

python -m pip vs pip

You'll see both forms. They do almost the same thing with one important difference: python -m pip uses the python on your PATH — the same one your scripts use. Bare pip uses whatever pip happens to come up first, which isn't always the same.

When you have more than one Python installed (easy to end up with on macOS), bare pip is how you get the confusing situation where "I installed the library but my code still says ModuleNotFoundError."

Rule of thumb: use python -m pip ... when you want certainty about which interpreter gets the package. Bare pip is fine for quick work when you're sure.

Installing a Package

The basic command:

python -m pip install requests

That fetches requests from PyPI, along with anything it depends on, and installs them. A minute later you can use it:

main.py
Output
Click Run to see the output here.

Installing multiple packages in one go:

python -m pip install requests pandas rich

Pinning a specific version:

python -m pip install "django==5.0.2"
python -m pip install "requests>=2.30,<3"

The quotes matter in some shells — they keep == and < from being interpreted as shell operators.

Upgrading and Uninstalling

python -m pip install --upgrade requests
python -m pip uninstall requests

--upgrade fetches the newest version that satisfies whatever constraint you specify. uninstall removes the package but not its dependencies; those stick around until you remove them explicitly.

To keep pip itself up to date:

python -m pip install --upgrade pip

Worth running once every few months. Newer pip versions catch more install problems and resolve dependencies better.

Seeing What's Installed

python -m pip list
python -m pip show requests

list shows every package installed in the current Python. show requests prints the version, location, dependencies, and license for that specific package — useful when you're wondering "which version of this am I actually using?"

requirements.txt: Writing Down Your Dependencies

When a project has more than a couple of libraries, write the list down. pip freeze does this for you:

python -m pip freeze > requirements.txt

That produces a file with one pinned dependency per line:

django==5.0.2
requests==2.31.0
rich==13.7.1

Anyone cloning your repo can reproduce the install with:

python -m pip install -r requirements.txt

pip freeze captures everything installed, including transitive dependencies. That's fine for exact reproducibility but noisy when you only want the top-level libraries your code actually imports. Many projects keep a hand-maintained requirements.txt of direct dependencies, and let pip resolve the transitive ones.

For modern projects, pyproject.toml (paired with tools like pip-tools, uv, poetry, or hatch) is taking over from requirements.txt. The concept is the same — "write the dependencies down, run a command to install them" — but the file format is more structured.

Always Install Into a Virtual Environment

Every real Python project should have a virtual environment. It's a project-local folder with its own python and its own installed packages — so pip install in one project doesn't affect any other.

The two-line setup:

python -m venv .venv
source .venv/bin/activate    # macOS / Linux
# or .venv\Scripts\activate on Windows

Once activated, python -m pip install requests installs into the venv. Your system Python stays clean. We cover this in more depth on the Virtual Environments page.

If you ever run pip install and see a warning about installing to the system Python (or a message telling you to pass --break-system-packages), stop. That's your cue to create a venv instead.

When pip Can't Install a Package

A few common failure modes and what they mean:

  • Could not find a version that satisfies the requirement … — usually a typo in the package name, or the package requires a newer Python than you have.
  • error: Microsoft Visual C++ 14.0 or greater is required (Windows) — the package has a native extension and needs a C++ build toolchain. Either install Microsoft's Build Tools or look for a pre-built wheel (most popular packages ship them).
  • Permission denied — you're trying to install into the system Python without root. The right fix isn't sudo pip install — it's a virtual environment.
  • ModuleNotFoundError after install — almost always a case where pip install landed the package in a different Python than the one running your script. Check which python and which pip (macOS/Linux) or where python / where pip (Windows). Or, more reliably, use python -m pip install ....

pip's Modern Alternatives

A few tools you'll see mentioned — all are pip-compatible and solve specific pain points:

  • uv — a much faster installer and resolver. Drop-in replacement for most pip commands.
  • pipx — installs command-line tools (like black, ruff, httpie) in isolated venvs so they're available globally without conflicting with project dependencies.
  • poetry and hatch — project managers that combine virtual environment handling, dependency resolution, and building into one tool.

You don't need any of them on day one. Learn pip first; reach for the others when the pain they solve becomes yours.

Next: Virtual Environments

Packages and virtual environments go together. You've seen why; the next page walks through venv in detail — creating, activating, deactivating, and the small conventions that keep Python projects organised.

Frequently Asked Questions

What is pip in Python?

pip is Python's package installer — the tool that downloads and installs third-party libraries from the Python Package Index (PyPI). pip install requests fetches the requests library and puts it where your Python interpreter can import it. It ships with every recent Python 3 install.

How do I install pip?

It comes with Python. If pip --version reports a missing command, run python -m ensurepip --upgrade or python -m pip install --upgrade pip. On macOS and Linux, use pip3 if plain pip isn't found — it points at the Python 3 install.

How do I update pip?

Run python -m pip install --upgrade pip. Using python -m pip instead of bare pip makes sure the upgrade targets the Python interpreter you're actually using — a small but important detail when multiple Pythons are installed.

Should I install packages globally or in a virtual environment?

Virtual environment, every time, for every project beyond a one-off script. Global installs cause version conflicts between projects and pollute your system Python. The venv module (built in) is the short answer — we cover it on the Virtual Environments page.

Learn to code with Coddy

GET STARTED