uv: Quick Python Package Manager Installation and Usage
Learn the installation and basic commands of uv, the fast and modern package manager that you can use instead of pip, virtualenv and pyenv in your Python projects.
Contents
Overview
In Python development processes, pip, Managing individual tools such as virtualenv, pip-tools and pyenv can be complex and slow. Developed with Rust, uv is a modern Python package manager that replaces all these tools, blazing fast and consisting of a single binary file. Developed by Astral, this tool offers 10 to 100 times faster performance than traditional methods.
Installation
The safest and recommended method for installing uv on Linux systems is to use the official installation script:
curl -LsSf https://astral.sh/uv/install.sh | shNote: After installation, ensure that the
PATHsettings are updated by runningsource ~/.bashrcor restarting your terminal.
Project Initialization and Dependency Management
Follow these steps to create a new Python project:
- Create and start the project directory:
uv init project-name - Add dependency:
uv add requests - Add development dependency:
uv add --dev pytest - Remove dependency:
uv remove requests
uv automatically creates a .venv environment on the first dependency addition and locks the project by locking the uv.lock file. makes it reproducible.
Code Execution
You do not need to activate the virtual environment manually. The uv run command automatically synchronizes the project's dependencies and runs the code:
uv run python main.pyManaging Python Versions
uv can download and manage different Python versions, regardless of the Python version on your system:
- Listing available versions:
uv python list - Installing a specific version:
uv python install 3.12
CLI Tools
uv tool install ruff command to install CLI tools in isolation without damaging your system, and uvx ruff check . to run them temporarily without installation.
Problem. Troubleshooting
Warning: If you are getting "externally-managed-environment" error, use
pipx install uvor standalone install script instead of system package manager.