Bàsic

uv és un gestor de paquets i projectes Python d'última generació construït amb Rust

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:

Utilitza irm per descarregar l’script i executa’l amb iex:

powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

Python

Per executar codi Python necessites un programa que interpreti el codi i l’executi.

El primer que has de fer és instal·lar l’última versió de Python

Obre un termina de Powershell.

Install the latest Python version:

uv install python

Once Python is installed, it will be used by uv commands automatically

Un cop Python està instal·lat, serà utilitzat automàticament per les comandes de uv.

uv only installs a versioned executable by default que pots executar amb py a windows:

> py

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

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

To view available and installed Python versions:

uv python list

See the python list documentation for more details.

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.

Crea un fitxer hello.py amb Notepad:

notepad hello.py

Escriu i guarda un script molt senzill:

print

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 test
uv run example.py hello world!

uv -scripts

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 installInstal·la versions de Python
uv python listMostra les versions de Python disponibles
uv python findTroba una versió de Python instal·lada
uv python pinFixa el projecte actual per utilitzar una versió específica de Python
uv python uninstallDesinstal·la una versió de Python

Installing Python

Versions

A Python version is composed of a Python interpreter (i.e. the python executable), the standard library, and other supporting files.

Versions

uv supports downloading and installing CPython and PyPy distributions.

CPython distributions

As Python does not publish official distributable CPython binaries, uv instead uses pre-built distributions from the Astral python-build-standalone project.

The uv Python distributions are self-contained, highly-portable, and performant.

These distributions have some behavior quirks, generally as a consequence of portability; see the python-build-standalone quirks documentation for details. Additionally, some platforms may not be supported (e.g., distributions are not yet available for musl Linux on ARM).

PPyPy distributions

PyPy distributions are provided by the PyPy project.

Windows

On Windows, installation of managed Python versions will register them with the Windows registry as defined by PEP 514.

After installation, the Python versions can be selected with the py launcher, e.g.:

uv python install 3.13.1
py -V:Astral/CPython3.13.1

On uninstall, uv will remove the registry entry for the target version as well as any broken registry entries.

TODO