LinuxCommandLibrary

uv-venv

Create Python virtual environments

TLDR

Create a virtual environment in the default location (.venv)

$ uv venv
copy

Create a virtual environment at a specific path
$ uv venv [path/to/venv]
copy

Create using a specific Python version
$ uv venv --python [3.12]
copy

Create with a custom prompt prefix
$ uv venv --prompt [my_project]
copy

Create and allow overwriting existing environment
$ uv venv --allow-existing [venv_name]
copy

SYNOPSIS

uv venv [LOCATION] [OPTIONS]

PARAMETERS

LOCATION
    The directory path where the virtual environment should be created. If omitted, defaults to .venv in the current directory.

-h, --help
    Display a help message and exit.

-p <PYTHON>, --python <PYTHON>
    Specifies the Python interpreter to use for the new virtual environment. Can be a name (e.g., python3.10) or a path (e.g., /usr/bin/python3.9).

--prompt <PROMPT>
    Sets a custom prefix for the virtual environment's command prompt when activated.

--seed
    Installs pip, setuptools, and wheel into the newly created virtual environment. This is often desired for compatibility with existing workflows or tools.

-f, --force
    Forces the creation of the virtual environment, overwriting any existing directory at the specified location without a prompt.

DESCRIPTION

uv venv is a sub-command of uv, a high-performance Python package management tool written in Rust. It provides a significantly faster and more reliable way to create isolated Python virtual environments compared to traditional methods like python -m venv. Virtual environments are essential for managing project dependencies, preventing conflicts between different projects by isolating their respective Python interpreters and package installations. uv venv integrates seamlessly with uv's robust dependency resolution and package installation capabilities, making it a powerful alternative for Python developers seeking speed and efficiency.

CAVEATS

Newer Tool: uv is relatively new compared to venv or virtualenv. While stable, its features and behavior might evolve rapidly.
Rust-based: Being written in Rust, it is generally very fast and memory-efficient.
Seed Behavior: By default, uv venv creates an environment without pip, setuptools, and wheel (as uv doesn't need them internally). The --seed flag is required to include them, which is different from python -m venv's default behavior.

<B>DEFAULT LOCATION</B>

If no location is provided, uv venv defaults to creating the environment in a directory named .venv in the current working directory.

<B>ACTIVATION</B>

Like other virtual environments, a uv venv environment needs to be activated (e.g., source .venv/bin/activate on Linux/macOS, .venv\Scripts\activate on Windows) to use its isolated Python interpreter and installed packages.

HISTORY

uv was developed by Astral (now part of the rye project) with the goal of creating a blazing-fast, robust, and reliable Python package management tool. It's written in Rust, leveraging its performance characteristics to significantly outperform traditional Python tools like pip and venv for dependency resolution and environment creation. uv-venv is a direct result of this effort, providing a modern and efficient way to manage Python isolation. It gained significant traction quickly due to its speed and reliability.

SEE ALSO

python -m venv, virtualenv(1), pip(1), conda(1), rye(1)

Copied to clipboard