- A python package and project manager written in Rust
- A drop in replacement for
pip,pip-tools,virtualenv- (python) Virtual environment using pip and venv
uvVSpip virtualenvpiponly handles package management andvirtualenvhandles only environment creation →uvcombines both functionalities in a single tooluv→ often 10~100x faster, uses significantly less memory, better conflict resolution
- Virtual environment
- What it does
- Manages
pyproject.toml, lockfiles (uv.lock), and project-specific virtual environments automatically. - Downloads and installs Python interpreters on demand
- Installs and runs Python CLI tools in isolated environments
- Uses global cache
- Manages
mac install & usage
brew install uv
uv version
uv init explore-uv
cd explore-uv
tree -a
.
├── .gitignore
├── .python-version
├── README.md
├── hello.py
└── pyproject.toml
- git is automatically initialized and main git-related files like
.gitignore+ emptyREADME.mdare generated .python-version→ contains the Python version used for the projpyproject.toml→ the main configuration file for project metadata and dependencies- if u wanna change the python version, check if version is ok in
pyproject.toml, then go.python-version& change, thenuv sync - then this creates a new virtual env in the proj directory →
uv pip install -e.
- if u wanna change the python version, check if version is ok in
hello.py→ simple file to help u get started quickly
Adding dependencies
uv add requests
uv add requests=2.1.2
uvcombines the environment creation & dependency installation- the 1st time you run the
addcommand, UV creates a new virtual environment in the current working directory and installs the specified dependencies - on subsequent runs, UR reuses the existing virtual env and only install/update the newly requested packages
- the 1st time you run the
add- when u
add, UV uses a modern dependency resolver that analyzes the entire dependency graph to find a compatible set of package versions that satisfy all requirements - automatically generates + updates
uv.lockfile- records exact versions of all dependencies & sub-dependencies
- u can maintain
requirements.txttoouv export -o requirements.txt→ generates arequirements.txtfrom a uv lock file
- updates the
pyproject.toml
- when u
uv remove scikit-learn
uv run hello.py
run- use when u wanna execute single file
runensures that script is executed in the virtual env UV created
pip to uv migration
pip freeze > requirements.txt
uv init.
uv pip install -r requirements.txt
more on pip vs uv
- caching
pip→ caches downloaded wheel files + source distributions, but unpacks and copies the actual package files into each individual virtual environment (consuming more disk space and time)uv→ uses global cache mechanism - if u install the same version of a package in multiple virtual envs on the same machine,uvlinks to the cached version rather than copying the files over and over
- tool consolidation
pip & virtualenv→ multistep → 1st makevirtualenvthen usepipto manage packagesuv→ single unified tool → use theuvCLI to create envs and manage packages