Getting started with UV - An extremely fast Python package and project manager
+ Instructions on how to switch from poetry to uv
How to set up UV locally
1. Install uv
curl -LsSf https://astral.sh/uv/0.4.6/install.sh | sh2. By default uv is installed to ~/.cargo/bin. Run the following command in the terminal to add uv to your system's PATH
source $HOME/.cargo/env 3. Verify installation by running the command below. You should see an output with the version number indicating successful installation
uv --version Switch from poetry to uv in an existing project
If you wish to use uv instead in an existing Python project using poetry
1. In the root folder of your poetry project with pyproject.toml file, run the following commands
Download the bash script
wget https://raw.githubusercontent.com/MridulaMaddukuri/poetry-uv-project/master/poetry-to-uv.shModify the pyproject.toml file to be uv compatible
bash poetry-to-uv.sh2. To update your project to uv
uv syncThis will create a `uv.lock` file in your root folder
3. Run python scripts
uv run path/to/your/script.pyCreating a new project
To create a new project
uv init my-project
cd my-projectThis will create the following files in `my-project` directory. To view the files with the command tree -a
.
├── .python-version
├── README.md
├── hello.py
└── pyproject.toml The .python-version file contains the project's default python version. uv refers to this file while creating the project's virtual environment
Create a virtual environment and uv.lock file in the root folder, run the command
uv syncCheck the contents of your directory using the command tree -a
.
├── .python-version
├── .venv
│ ├── .gitignore
│ ├── CACHEDIR.TAG
│ ├── bin
│ ├── lib
│ └── pyvenv.cfg
├── README.md
├── hello.py
├── pyproject.toml
└── uv.lock.venv contains your project’s virtual environment
To create a virtual environment using a specific Python version
uv venv --python 3.11.6
-- activate the virtual environment
source .venv/bin/activateAdd dependencies to pyproject.toml file with one of the following commands
uv add ruffTo install specific version of a library
uv add 'ruff==0.6.5'Add development dependencies
uv add ruff --devRemove dependencies
uv remove ruffRun the Python script `hello.py` in this directory with `` command
uv run hello.pyUninstall uv
https://docs.astral.sh/uv/getting-started/installation/#uninstallation
Links
Bash script to convert pyproject.toml file to uv compatible format
