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 after the 'uv init', you can copy the project structure template 
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.12.3
# 2. You can also pin the version to a file in project root.
uv python pin 3.12.3 # Default is higher that satisfies pyproject.toml
# 3. Create the .venv with that version
uv venv --python 3.12.3

Activate the virtual environment

source .venv/bin/activate

Add dependency package

uv add pandas
# adds to development requirements
uv add --dev pytest jupyter  
uv add --group dev pytest jupyter

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

Sync with requirements (Install dependencies)

# sync the changes in pyproject.toml (for ex. after changing python version)
uv sync
uv sync --dev
# Or sync to virtual environment using pip install
uv pip install -r pyproject.toml
# If there is a non-pypi-package
uv pip install -r pyproject.toml --index-strategy unsafe-best-match
# If there is a conflict [Use --no-deps flag]
uv pip install -r pyproject.toml --index-strategy unsafe-best-match **--no-deps**

List installed packages

uv pip list
# View dependencies
uv tree