Install UV on the system
curl -LsSf <https://astral.sh/uv/install.sh> | sh
Initialize a Project
# takes the directory name as project
uv init
# or name your project and open the project directory
uv init myproject && cd myproject
# Note: Commands initializes **.git/** directory ****and **pyproject.toml** file
Add a Project Template to the project
Optionally you can also use this to copy the project structure template on the project folder.
bash <(curl -s <https://gist.githubusercontent.com/sglbl/27d51879413b86a962455fb37594e2d3/raw/setup_template_for_uv.sh>)
Create a virtual environment with the name .venv
# Default name: .venv
uv venv
# You can also name it # UNRECOMMENDED
uv venv .venv2 # you need to run: export UV_PROJECT_ENVIRONMENT=.venv2
# OR WITH A SPECIFIC VERSION
# 1. install other python with:
uv python install 3.10.12
# 2. You can also pin the version to a file in project root.
uv python pin 3.10.12 # Default is higher that satisfies pyproject.toml
# 3. Create the .venv with that version
uv venv --python 3.10.12
# Note: You can set the uv downloaded python version over system python
export UV_MANAGED_PYTHON=true
Activate the virtual environment
source .venv/bin/activate
Add package
uv add pandas
# adds to development requirements
uv add --dev pytest jupyter
uv add --group dev pytest jupyter
Upgrade package
uv add "PACKAGE>=VERSION" --upgrade-package PACKAGE
# Example: uv add "marimo>=0.19.7" --upgrade-package marimo
Install a package from extra index url
# Example: Add torch cpu version
uv add torch --index <https://download.pytorch.org/whl/cpu> --index-strategy unsafe-best-match
Remove dependencies
uv remove loguru
uv remove --dev jupyter