Package Management had no intro, so its meta description fell back to generic text and readers got no guidance on which tool to pick. Co-Authored-By: Claude <noreply@anthropic.com>
5.7 KiB
Whatever you need from PyPI, uv installs and locks it, and uv-build packages pure Python. Conda is more than a Python package manager: it handles any language.
How to choose:
- A project's dependencies, lockfile, and Python versions: uv
- Packaging a pure-Python project: uv-build
- Non-Python dependencies, like C libraries or R: conda
- Nothing beyond what ships with Python: pip
- A project already on Poetry: Poetry
- Tests across several Python versions: Hatch
- Command-line apps, each in its own environment: pipx
- C or C++ extension modules: setuptools
- Build hooks or a flexible project layout: Hatchling
uv is one tool for your project's dependencies, lockfile, and Python versions, and it covers what you'd otherwise use pip, pipx, and Poetry for. Start with uv init, add dependencies with uv add, and run your code with uv run, which syncs the environment with the lockfile first. Its uv pip commands are meant for projects not ready to move away from pip.
uv-build is uv's own build backend, which its docs call a great choice for most Python projects. It's for pure-Python code, aims to need no configuration, and by default expects your package in src/<package_name>/.
conda manages packages in any language, Python included, so it fits projects that need compiled non-Python libraries next to their Python ones. Install it with Miniforge, which uses the free conda-forge channel. Miniconda and the Anaconda Distribution use Anaconda's repository instead, which may require a commercial license. In a conda environment, install as much as you can with conda before you use pip for the rest. To change the environment later, create a new one rather than running conda after pip.
pip is the standard tool to install packages from PyPI, and it ships with most Python installations. Run it as python -m pip, so it installs into the interpreter you name, and use it inside a virtual environment. To repeat an install, pin every version in a requirements file generated by pip freeze. By default, pip doesn't check downloads for tampering, so for deployments its docs recommend hash-checking mode.
Poetry manages dependencies and packaging, with a lockfile for repeatable installs. Install it in its own virtual environment, with pipx for example, and never in the project it manages.
Hatch is a Python project manager for environments, builds, and publishing. You never create its environments by hand: the first command you run in one creates it. Define a matrix to run the same tests across Python versions. For most projects, hatch test runs pytest and coverage.py with no test environment of your own.
pipx installs command-line apps each in its own virtual environment and puts their commands on your PATH, and pipx run runs an app without installing it. If you already use uv, its tool command does the same job. pipx's docs suggest pipx when you need its extras, like installing an app system-wide.
setuptools builds C and C++ extension modules, and Hatch's docs recommend it when you need them. Keep your config in pyproject.toml and only the dynamic parts in setup.py. Build with python -m build instead of running setup.py.
Hatchling is the build backend the Python Packaging User Guide's tutorial uses by default. It supports plugins and build hooks, and uv's docs point to it when you need build scripts or a more flexible project layout.
Whichever tool builds your package, declare the backend in pyproject.toml's [build-system] table and your metadata in the standard [project] table, which most build backends understand. For an app, commit uv.lock or poetry.lock, so every machine installs the same versions. A library's lockfile doesn't reach the apps that install it, since they resolve its dependencies themselves.