Introducció
uv supports managing Python projects, which define their dependencies in a pyproject.toml
file.
Creating a new project
You can create a new Python project using the uv init
command:
uv init hello
cd hello
Alternatively, you can initialize a project in the working directory:
mkdir hello
cd hello
uv init
uv will create the following files:
├── .gitignore
├── .python-version
├── README.md
├── main.py
└── pyproject.toml
The main.py
file contains a simple “Hello world” program. Try it out with uv run
:
uv run main.py
Project structure
A project consists of a few important parts that work together and allow uv to manage your project.
In addition to the files created by uv init
, uv will create a virtual environment and uv.lock
file in the root of your project the first time you run a project command, i.e., uv run
, uv sync
, or uv lock
.
…
Managing dependencies
You can add dependencies to your pyproject.toml
with the uv add
command.
This will also update the lockfile and project environment:
uv add polars
Gestionat l’entorn virtual
Managing Python Virtual Environments with UV: A Comprehensive Guide