uv
Installation
curl -LsSf https://astral.sh/uv/install.sh | sh
USTC mirror
~/.config/uv/uv.toml
[[index]]
url = "https://mirrors.ustc.edu.cn/pypi/simple"
default = true
Usage
# init project
uv init project-name --python 3.xx
cd project-name
uv venv --seed
# add dependency
uv add xxx
# install directly to venv, will not be managed by uv
# and will not be added to pyproject.toml
uv pip install xxx
# run
uv run xxx.py
# activate venv
source .venv/bin/activate
# deactivate venv
deactivate
Jupyter
#Add ipykernel as a dev dependency.
uv add --dev ipykernel
uv pip install jupyterlab
.venv/bin/jupyter lab
PyTorch
PyTorch would be installed from PyPI, which hosts CPU-only wheels for Windows and macOS, and GPU-accelerated wheels on Linux (targeting CUDA 12.6)
uv add torch torchvision
FastAPI
uv add fastapi --extra standard
uv run fastapi dev
Dockerfile
# Use the official Python image.
# https://hub.docker.com/_/python
FROM python:3.12-slim
# Install uv.
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
# Copy the application into the container.
COPY . /app
# Install the application dependencies.
WORKDIR /app
RUN uv sync --frozen --no-cache
# Run the application.
CMD ["/app/.venv/bin/fastapi", "run", "app/main.py", "--port", "80", "--host", "0.0.0.0"]