DEV Community

Cover image for 🐍 Don't Need to Create requirements.txt and .venv Manually [UV]
Sajidur Rahman Shajib
Sajidur Rahman Shajib

Posted on

🐍 Don't Need to Create requirements.txt and .venv Manually [UV]

We need something better than pip β€” and that's where uv comes in. It’s a fast Python package manager and task runner that replaces pip, venv, and even parts of poetry, without the extra overhead.

Though previously I wrote Do not use 'pip freeze' and Best way to create requirements.txt. You can read them...


🏁 First install uv

You can find the installation instructions for uv here

πŸ”§ uv init: Instant Project Setup

uv init
Enter fullscreen mode Exit fullscreen mode

This command creates a boilerplate pyproject.toml and sets up your .venv β€” no manual steps needed. It automatically detects your Python version and prepares a minimal project environment.


βž• uv add: Add Dependencies Instantly

Need a package like rich?

uv add rich
Enter fullscreen mode Exit fullscreen mode

This adds it to your pyproject.toml, installs it, and updates your uv.lock. No need to touch requirements.txt.

Example usage with rich:

from rich import print

print("[bold green]Hello from UV-powered project![/bold green]")
Enter fullscreen mode Exit fullscreen mode

πŸš€ uv run: Run with Environment

Instead of manually activating .venv, use:

uv run main.py
Enter fullscreen mode Exit fullscreen mode

This runs your app inside the managed environment automatically.

Yes, you can still run with python main.py, but that means you'll have to activate .venv manually:

source .venv/bin/activate
Enter fullscreen mode Exit fullscreen mode

πŸ”„ After Clone/Pull a UV based project

First run

uv venv
Enter fullscreen mode Exit fullscreen mode

and then install all packages from pyproject.toml

uv sync
Enter fullscreen mode Exit fullscreen mode

πŸ“š Want More?

There’s more you can do: uv pip, uv pip freeze, uv sync --update, and more. You can even change Python versions or set a specific version in .python-version β€” check it out in their docs.

Top comments (0)