UV Venv – Fast Python Environment Setup
If you have been working with Python for any length of time, you know that virtual environments are essential for managing dependencies and keeping projects isolated. For years, developers have relied on python -m venv
or tools like virtualenv
to create these environments.
Now, there’s a faster, smarter way — uv
, a modern Python package and environment manager from the creators of ruff
. In this guide, we’ll cover two essential commands:
uv venv -p
uv pip install cluster main
By the end, you’ll know how to create high-performance virtual environments, install your dependencies quickly, and avoid common pitfalls.
What is uv
?
uv
is a fast Python package and environment manager built in Rust. It combines the best features of multiple tools:
pip
— for installing Python packages.venv
— for creating virtual environments.pipx
— for installing standalone Python tools.
Key Benefits of uv
- Speed — Rust-powered and much faster than Python’s built-in tools.
- Built-in environment management — Create and manage venvs without extra commands.
- Cross-platform consistency — Works the same way on Windows, macOS, and Linux.
- Simplified dependency management — No need to juggle multiple tools.
Understanding uv venv -p
The command:
uv venv -p python3.11
means:
uv
→ Run theuv
CLI.venv
→ Create a virtual environment.-p
/--python
→ Specify the Python interpreter to use.
Without -p
, uv
uses the system’s default Python. With -p
, you can target any installed version.
Example:
uv venv -p /usr/local/bin/python3.12
This will:
- Create a
.venv
directory in your current folder. - Use Python 3.12 as the interpreter.
- Prepare the environment for package installations via
uv pip
.
Why Use -p
?
In real-world projects, you often need to match a specific Python version — especially if production servers use an older version. If you use python -m venv
without specifying, you might end up with a mismatch.
uv venv -p
ensures your virtual environment uses exactly the version you want.
Creating a Virtual Environment with uv venv -p
Here’s the full process:
# 1. Navigate to your project folder
cd my_project
# 2. Create the environment with a specific Python version
uv venv -p python3.10
# 3. Activate the environment
source .venv/bin/activate # Linux/macOS
.venv\Scripts\activate # Windows
Once activated, your shell prompt changes:
(.venv) user@machine:~/my_project$
Now you can install packages using uv pip install
.
Installing Packages with uv pip install
uv pip
works just like pip install
but faster.
Example:
uv pip install requests
This installs the requests
library into your .venv
.
What Does uv pip install cluster main
Do?
The command:
uv pip install cluster main
installs two packages into your current environment:
cluster
main
These can be:
- Public packages from PyPI.
- Local directories containing Python packages.
- Editable installs for development.
Editable example:
uv pip install -e ./cluster ./main
This is great for monorepo projects where you have multiple internal packages.
Why Combine uv venv -p
with uv pip install
?
A typical workflow for a new Python project might be:
# Create an environment with a specific version
uv venv -p python3.11
# Activate it
source .venv/bin/activate
# Install dependencies
uv pip install cluster main
This ensures:
- No dependency conflicts between projects.
- Easy reproducibility across machines.
- Production and local environments match.
Advantages Over Traditional Pip + Venv
Feature | python -m venv + pip |
uv |
---|---|---|
Speed | Slow | Very fast |
Version selection | No | Yes (-p ) |
Package caching | Limited | Built-in |
Cross-platform | Mostly consistent | Fully consistent |
Dependency resolution | Basic | Optimized |
Common Mistakes and How to Avoid Them
Forgetting
-p
Your environment may have the wrong Python version.
Check with:
python --version
Not activating the venv before install
- Packages might install globally instead of in your project.
Mixing
pip
anduv pip
- This can cause caching issues. Stick to one installer.
Example: Setting Up a Data Project
Imagine you have two packages:
cluster
→ your data clustering algorithms.main
→ the application entry point.
You could set it up like this:
# Create environment with Python 3.11
uv venv -p python3.11
# Activate it
source .venv/bin/activate
# Install both packages
uv pip install -e ./cluster ./main
Run your app:
python -m main