Bulut & Sanallaştırma
100%

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.

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 | sh

Note: After installation, ensure that the PATH settings are updated by running source ~/.bashrc or restarting your terminal.

Project Initialization and Dependency Management

Follow these steps to create a new Python project:

  1. Create and start the project directory: uv init project-name
  2. Add dependency: uv add requests
  3. Add development dependency: uv add --dev pytest
  4. 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.py

Managing 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 uv or standalone install script instead of system package manager.

Related Articles

View All