uv

uv is a modern tool for managing installations of Python and project dependencies.

In Python’s 30-year history, there have been a number of ways to install Python, Python software, and libraries for Python projects.

uv obsoletes most of them and provides the simplest and easiest way to manage Python projects and install Python software into your local environment.

Conda, especially via Pixi, is also useful for many projects, particularly with mixed dependency types. However, I usually use uv these days, unless I have specific needs for other software.

Once you have uv, you can use it to get any Python or Python package you need, but you first need to install uv itself. The uv installation instructions provide details on a variety of ways to install. I have a few recommendations:

Tip

See Dependencies with uv for more details on managing project dependencies with uv.

Recipes

Some useful uv commands:

  1. To create a virtual environment in the current directory with a specific Python version:

    $ uv venv -p 3.12
  2. To install a project and its dependencies into this virtual environment (assuming you ran uv venv in the project’s root directory, and the project is intended to be used with uv):

    $ uv sync
  3. To add a new package as a dependency to your project and install it into the environment:

    $ uv add pydantic
  4. To update all dependency versions:

    $ uv sync -U
  5. To run a command published as a Python package, installing it (in an isolated virtual environment) if needed:

    $ uvx run visidata
  6. To install a Python package as a “tool”, so it is available in multiple projects (through the uv tool interface):

    $ uv tool install visidata

    You can then run with:

    $ uv tool run visidata
  7. To install an arbitrary package into your current uv-managed Python environment:

    $ uv pip install visidata
    Warning

    Avoid using uv pip install in projects intended to be used with uv sync (a quick way to check: does it provide a uv.lock file?). Packages added with uv pip install are not tracked in the dependency files. However, the uv pip commands are very useful for managing virtual environments you create for other purposes, such as a collection of useful tools you want to run outside of projects.