Skip to main content
Basics

How to install a package in Python

Quick answer

In 2026: uv add <package> is fastest. pip install <package> works everywhere.

# Modern (2026 default):
# uv add requests

# Universal (works with any Python install):
# pip install requests

# Then in your code:
import requests
res = requests.get("https://api.github.com")

uv is the 2024-2026 successor to pip β€” 10-100x faster because it's written in Rust. `uv add pkg` also updates pyproject.toml + lockfile in one step, so your project stays reproducible.

pip still works everywhere and is fine for scripts and one-off environments. Prefer `python -m pip install pkg` over the bare `pip install pkg` β€” it guarantees you're using the pip attached to the Python interpreter you actually want.

Always install inside a virtual environment, not into system Python. On macOS/Linux especially, `pip install` at the system level can break the OS. `python -m venv .venv && source .venv/bin/activate` is the classic setup.

Variations

Create a venv (stdlib)

# One-time setup:
# python -m venv .venv
# source .venv/bin/activate   # macOS / Linux
# .venv\Scripts\activate      # Windows

Isolates your project from every other Python install.

Pin an exact version

# uv add requests==2.32.3
# pip install requests==2.32.3

Use == for exact, ~= for 'compatible with' (2.32.3 β†’ any 2.32.x).

Install multiple from a file

# uv sync            # reads pyproject.toml + uv.lock
# pip install -r requirements.txt

requirements.txt is the classic pip flow. pyproject.toml is the modern one.

Practise this in your browser

Every how-to has a live lesson. Free tier, no card.

Start free β†’

Unlock every lesson

Pro β€” $12/mo, unlimited AI, cancel any time.

See Pro plans β†’

Get one Python lesson + one career idea every Friday

No spam, no "buy our course now". Three bullets, every Friday. Unsubscribe with one click.

Related how-tos