UV
uv és un gestor de paquets i projectes Python d'última generació construït amb Rust
Introducció
Section titled “Introducció”uv
proporciona característiques essencials per al desenvolupament en Python — des de la instal·lació de Python i la programació de scripts senzills fins al treball en grans projectes que admeten múltiples versions de Python i plataformes.
Instal·la uv
amb Scoop:
scoop install uv
La interfície de uv es pot dividir en seccions, que es poden utilitzar de manera independent o conjunta.
Python
Section titled “Python”Si Python ja està instal·lat al teu sistema, uv
el detectarà i l’utilitzarà sense configuració. No obstant això, uv també pot instal·lar i gestionar versions de Python. uv
instal·la automàticament les versions de Python que falten segons sigui necessari — no cal instal·lar Python per començar.
uv python install | Instal·la versions de Python |
uv python list | Mostra les versions de Python disponibles |
uv python find | Troba una versió de Python instal·lada |
uv python pin | Fixa el projecte actual per utilitzar una versió específica de Python |
uv python uninstall | Desinstal·la una versió de Python |
Per instal·lar l’última versió de Python:
uv python install
Un cop Python està instal·lat, serà utilitzat automàticament per les comandes de uv
.
Installing a specific version
Section titled “Installing a specific version”To install a specific Python version:
uv python install 3.12
To install multiple Python versions:
uv python install 3.11 3.12
To install an alternative Python implementation, e.g., PyPy:
uv python install pypy@3.10
See the python install documentation for more details.
Reinstalling Python
Section titled “Reinstalling Python”To reinstall uv-managed Python versions, use --reinstall
, e.g.:
uv python install --reinstall
This will reinstall all previously installed Python versions. Improvements are constantly being added to the Python distributions, so reinstalling may resolve bugs even if the Python version does not change.
Viewing Python installations
Section titled “Viewing Python installations”To view available and installed Python versions:
uv python list
See the python list documentation for more details.
Scripts
Section titled “Scripts”A Python script is a file intended for standalone execution, e.g., with python <script>
.py. Using uv to execute scripts ensures that script dependencies are managed without manually managing environments.
Running a script without dependencies
Section titled “Running a script without dependencies”If your script has no dependencies, you can execute it with uv run
:
print("Hello world")
uv run example.py
Similarly, if your script depends on a module in the standard library, there’s nothing more to do:
import os
print(os.path.expanduser("~"))
uv run example.py
Arguments may be provided to the script:
import sys
print(" ".join(sys.argv[1:]))
uv run example.py testuv run example.py hello world!
Project
Section titled “Project”uv supports managing Python projects, which define their dependencies in a pyproject.toml
file.
Creating a new project
Section titled “Creating a new project”You can create a new Python project using the uv init
command:
uv init hellocd hello
Alternatively, you can initialize a project in the working directory:
mkdir hellocd hellouv 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
Section titled “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
Section titled “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
El contingut d'aquest lloc web té llicència CC BY-NC-ND 4.0.
©2022-2025 xtec.dev