uv installation
- For linux:
curl -LsSf https://astral.sh/uv/install.sh | sh
- For windows:
powershell -ExecutionPolicy ByPass -c “irm https://astral.sh/uv/install.ps1 | iex”
To intialise a project using uv
uv init first-project
uv will create the following files
├── .gitignore ├── .python-version ├── README.md ├── main.py └── pyproject.toml
.python-version stores the version of the python. It tells uv what python version to use. uv uses this python version to create the virtual environment
pyproject.toml contains the metadata of the project. It tells what are the dependencies used in the project and details about the project. to maintain project dependencies and project details, pyproject.toml can be manually edited.
[project]
name = "first-package"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = []
uv run
uv run creates a virtual environment and a uv.lock file when uv run is used first time.
uv run main.py
uv.lock file stores the project metadata such as dependencies in the project with their exact versions. It is managed by uv itself and not edited manually. This ensures same version of the dependencies will be used by developers with no version mismatch.
To check the version of your project
uv version