Python Package Managers⚓︎
What is python uv ?
UV is a high performance Python package manager and installer written in Rust. It serves as a drop-in replacement for traditional Python package management tools like pip, offering significant improvements in speed, reliability, and dependency resolution. It is design to address the common pain points in the Python ecosystem such as slow installation times, dependencies conflicts and environment management complexity. It is 10-100x faster than traditional.
What are the key features of the uv ?
- Lightning-fast package installation and dependency resolution
- Compatible with existing Python tools and workflows
- Built-in virtual environment management
- Support for modern packaging standards
- Reliable dependency locking and reproducible environments
- Memory-efficient operation, especially for large projects
Remark : From small scale personal projects to the large scale industry project UV provides a robust and efficient solution for package management.
What are the difference amongs the UV, Poetry, PIP, Conda, and virtualenv package managers ?
- How to install the UV package manager ?
- Linux/MacOS :
$ curl -LsSf https://astral.sh/uv/install.sh | sudo sh - Windows(Powershell with Admin Privilage) :
$ powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex" - Inside Virtual Environment(python/conda) :
$ pip install uv# Make sure you have a virtual environment activated - Verify the installation :
uv version - New Project Initialization(similar to git repository) :
uv init project_name - Then change to the
project_namedirectory :cd project_nameand see the tree of directory :tree -a├── .gitignore : git auto initialized ├── .python-version : python version used by project ├── README.md ├── hello.py : to check project setup properly done or not. └── pyproject.toml : main config file for the project meta data and dependencies - Addition of Initial Dependencies to the project : UV offers to combine the env creation and dependecies installation into a single command :
uv add scikit-learn xgboost
Remarks : UV combines the environment creation and dependency installation into a single command and UV updates the pyproject.toml and uv.lock files after each add command.
6. Remove dependencies fron env and pyproject.toml file : uv remove scikit-learn
7. Running python script with UV : uv run hello.py
8. How to manage the python versions in UV ?
It provides a command :uv python to use the particular python version for the project. Let's explore how to use this command
- Listing existing python versions : uv python list --only-installed
- Changing the python version for the project : requires-python = ">=3.9" Then call : uv sync
-
References⚓︎
- https://www.datacamp.com/tutorial/python-uv