TExcelTAD
Home › Python Packaging: pip, venv, Poetry & uv › The Python Packaging Landscape

The Python Packaging Landscape

Python's packaging story has a reputation for being confusing, and for years it deserved it: setup.py, easy_install, eggs, distutils, pip, virtualenv, pipenv, conda, poetry, pdm, hatch, and now uv. The good news is that since about 2020 the ecosystem has settled on a small set of standards (PEPs), and every modern tool implements the same ones. Learn the standards and the tools become interchangeable front ends.

Who this course is for

You can write Python: functions, modules, imports, and you have run pip install at least once. If not, work through Python first, in particular its Python PIP and Virtual Environments lessons; this course builds on them and goes much deeper. You don't need to know Poetry or uv yet.

The moving parts

Every Python packaging tool deals with the same five jobs. Keep this table in mind; most confusion comes from mixing up which tool does which job.

Job Standard Tools
Isolate an environment per project venv module, pyvenv.cfg (PEP 405), PEP 668 "externally managed" python -m venv, virtualenv, uv venv, Poetry and uv create them for you
Describe a project pyproject.toml [project] table (PEP 621) any editor; poetry/uv edit it with add and remove
Build a distribution build backends (PEP 517/518), wheel format (PEP 427) python -m build, uv build, poetry build; backends: setuptools, hatchling, poetry-core, flit-core, uv_build
Resolve and install dependencies version specifiers (PEP 440), Simple Repository API (PEP 503) pip, uv pip, poetry install, uv sync
Lock exact versions tool lockfiles (poetry.lock, uv.lock), pylock.toml (PEP 751) pip freeze, pip-tools, Poetry, uv
Publish to an index upload API, trusted publishing twine, uv publish, poetry publish

Two kinds of files move through this pipeline: a source distribution (sdist, a .tar.gz of your source plus metadata) and a wheel (a .whl zip that is ready to unpack into an environment). You'll build both, open them up and publish them.

A first look

Here's the whole pipeline in one session: create a virtual environment, install a package from an index, and use it. The second half does the same with uv, the newest tool, which creates the environment, writes pyproject.toml and a lockfile, and runs the code in one go.

bash · try it yourself
python3 -m venv .venv
. .venv/bin/activate
pip install -q rich==15.0.0
python -c 'import rich; from importlib.metadata import version; print("rich", version("rich"), "from", rich.__file__)'
deactivate
echo "--- the same with uv"
uv init -q --no-package demo && cd demo
uv add -q rich==15.0.0
uv run python -c 'from importlib.metadata import version; print("rich", version("rich"))'
ls -A
rich 15.0.0 from /home/learner/.venv/lib/python3.13/site-packages/rich/__init__.py
--- the same with uv
rich 15.0.0
.git
.gitignore
.python-version
.venv
README.md
main.py
pyproject.toml
uv.lock

The first half used three separate tools (the venv module, pip, and you remembering what you installed). The second half got a project file, an environment (.venv) and a lockfile (uv.lock) without asking.

How the sessions in this course run

Every bash session here is a real terminal session, recorded in a Linux container without network access:

Tool Version
CPython 3.13.17 (the only interpreter in the box)
pip 26.2.2
uv 0.13.5
Poetry 2.5.1 (poetry-core 2.5.0)
build / twine / virtualenv 1.6.1 / 7.0.0 / 21.14.13

Instead of pypi.org the container runs a local package index (pypiserver) at http://127.0.0.1:8080/simple/, holding a fixed set of packages: requests (2.34.2 and 2.31.0), rich (15.0.0 and 13.9.4), attrs (26.1.0 and 24.2.0), packaging (26.3 and 24.2), click (8.5.0 and 8.1.8), pytest, hatchling, setuptools, build, twine and their dependencies. A few conventions follow from that:

  • pip and uv are already pointed at the local index (through the PIP_INDEX_URL and UV_DEFAULT_INDEX environment variables). On your machine they use pypi.org by default and you don't need to set anything.
  • Poetry is configured per project, so every Poetry session starts with poetry source add --priority=primary local http://127.0.0.1:8080/simple/. You won't need this line against PyPI.
  • You can upload to the local index as user learner (password learner). Uploads disappear when the session ends.
  • The system Python is marked "externally managed", like Debian's and Ubuntu's: pip install outside a virtual environment is refused. Sessions always create an environment first, which is the right habit anyway.
  • Each session starts in an empty home directory and creates its files with cat > file <<'EOF' heredocs.

A runnable model: what "installing" means

Strip away the network and the resolver, and installing a wheel is just unzipping files into site-packages and recording what was installed. This model "installs" two fake wheels into a dictionary that stands for the environment, then lists it the way pip list does:

python · try it yourself
wheels = {
    "greet-1.0.0-py3-none-any.whl": {
        "greet/__init__.py": "def hello(): ...",
        "greet-1.0.0.dist-info/METADATA": "Name: greet\nVersion: 1.0.0\nRequires-Dist: colour>=2",
    },
    "colour-2.1.0-py3-none-any.whl": {
        "colour/__init__.py": "RED = 31",
        "colour-2.1.0.dist-info/METADATA": "Name: colour\nVersion: 2.1.0",
    },
}
site_packages = {}

def install(wheel):
    for path, text in wheels[wheel].items():
        site_packages[path] = text           # "unzip" into site-packages
    print("installed", wheel)

def pip_list():
    for path, text in sorted(site_packages.items()):
        if path.endswith(".dist-info/METADATA"):
            meta = dict(line.split(": ", 1) for line in text.splitlines())
            print(f"{meta['Name']:<8} {meta['Version']}")

install("colour-2.1.0-py3-none-any.whl")
install("greet-1.0.0-py3-none-any.whl")
pip_list()
print(len(site_packages), "files in site-packages")
installed colour-2.1.0-py3-none-any.whl
installed greet-1.0.0-py3-none-any.whl
colour   2.1.0
greet    1.0.0
4 files in site-packages

That's genuinely how it works: pip list reads the *.dist-info folders in site-packages, nothing more. Everything else in this course (resolving colour>=2, choosing the right wheel for your platform, building wheels from source, locking) is about deciding which files to unzip.

Test yourself

Which file describes a modern Python project's name, version and dependencies?

  1. setup.cfg
  2. requirements.txt
  3. pyproject.toml ([project] table)
  4. MANIFEST.in

What is a wheel?

  1. A compressed copy of a Git repository
  2. A ready-to-install zip archive with the package's files and metadata
  3. A lockfile format
  4. A virtual environment

How does pip list know what is installed?

  1. It asks the package index
  2. It reads the *.dist-info metadata folders in site-packages
  3. It parses requirements.txt
  4. It keeps a database in ~/.pip