UV Tutorial Part 1: Lightning-Fast Old-Style Python Project Management With UV

- Part 1: Lightning-Fast Oldstyle Python Project Management with UV
- Part 2: Creating and Managing Python Projects with UV
- Part 3: Installing PyTorch with CUDA
Introduction
Hey there! If you’re used to managing your Python projects with tools like pip, pyenv, virtualenv, or conda, I’ve got some exciting news for you. There’s a tool called uv (Universal Virtualenv) that’s going to revolutionize your workflow. It’s unbelievably fast – we’re talking 10-100x faster than pip. Let’s dive into how you can get started with uv and make your project management a breeze.
Installation Guide
First things first, let’s get uv installed on your system.
Windows Installation
If you’re on Windows, open PowerShell and run:
|
|
Linux/Mac Installation
For those using Linux or Mac, you can install uv with this command:
|
|
Installing via pip
Alternatively, you can install uv using pip:
|
|
Keeping UV Updated
To keep uv up to date, simply run:
|
|
Python Version Management
One of the coolest features of uv is its ability to manage different Python versions effortlessly. To see the list of available Python versions, use:
|
|
Traditional Python Project Setup vs UV Approach
Let’s compare the traditional way of setting up a Python project with the uv approach.
Traditional Method with virtualenv
Here’s how you might traditionally set up a new Python project using pip and virtualenv:
- Create a new directory
- Create a virtual environment:
virtualenv venv - Activate the virtual environment:
- Linux:
source .venv/bin/activate - Windows:
.\venv\Scripts\activate
- Linux:
- Install packages:
pip install requests - Generate requirements:
pip freeze > requirements.txt
Project Migration (Traditional)
When you want to move your project to another machine, you typically:
- Copy the project directory
- Create a new virtual environment
- Install dependencies:
pip install -r requirements.txt
Modern Approach with UV
Now, let’s see how uv can simplify this process and make it much faster:
- Create a new directory
- Create a virtual environment:
uv venvoruv venv --python 3.10for a specific Python version - Activate the virtual environment:
- Linux:
source .venv/bin/activate - Windows:
.\venv\Scripts\activate
- Linux:
- Install packages:
uv pip install requests - Generate requirements:
uv pip freeze > requirements.txt
Project Migration with UV
Moving your project to another machine with uv is a breeze:
- Copy the project directory
- Create a virtual environment:
uv venvoruv venv --python 3.10 - Install dependencies:
uv pip sync requirements.txt
Converting Existing virtualenv to UV
Already using a traditional virtualenv? No problem! Converting it to uv is super simple:
- Navigate to your project directory with the existing virtual environment.
- Run:
uv initto adopt the existing environment. - Convert dependencies:
uv add -r requirements.txtto createpyproject.tomlanduv.lockfiles.
Key Benefits of UV
To sum it up, here are some key benefits of using uv:
- Significantly faster package installation
- Better dependency management
- Easy Python version control
- Seamless conversion from existing virtualenv setups
What’s Next?
Stay tuned for Part 2, where we’ll explore how to create new projects with uv, add packages, and manage your project like a pro. In part 3, we will talk installing PyTorch with CUDA.
Related Content
- UV Tutorial Part 2: Creating and Managing Python Projects With UV
- UV Tutorial Part 3: Installing PyTorch With CUDA