# Virtual Environments and uv

> Each Python project gets its own packages in a virtual environment. A version manager swaps the language. And uv does both in one tool.

**Course:** [Code Editors and Package Managers](https://learn.benibix.com/learn/development-tools)  
**Time:** 12 min

**After this lesson you can:**

- Make and turn on a virtual environment
- Switch versions with a version manager
- Start a Python project with uv

## How each project keeps its own packages and versions

A virtual environment is a folder that holds the Python packages for one project. While it is turned on, pip installs into that folder only. So two projects can use two versions of one package, and both still work. Python has had a tool to make one built in since version 3.3, in 2012.

Without one, every project shares the one Python your computer came with. Project A needs version 2.20 of a package and project B needs 2.31. Whichever you installed last wins, and the other project breaks.

Turning it on changes your terminal so that python and pip point into the folder. On macOS and Linux you run source .venv/bin/activate. On Windows the script sits in .venv\Scripts instead. The name (.venv) then appears at the start of the line, which is how you know it worked.

A version manager does the same for the language itself. It keeps several versions of Python or Node.js on one computer and switches between them. pyenv does it for Python and nvm for Node.js. A small file in the project, such as .nvmrc, names the version that project needs.

uv is a newer tool that does all of this at once. It is written in Rust, and its makers say it is 10 to 100 times faster than pip. One command sets up a project with its own virtual environment and lockfile. It can also install Python versions, so it replaces pyenv too.

With uv you add a package with uv add, not pip install. That way it lands in the project's list and its lockfile. You run code with uv run. It uses the project's own folder of packages, so you never have to turn it on.

The common mistake is forgetting to turn the environment on. pip then installs into the main Python, and the project cannot find the package. Look for (.venv) at the start of the line before you install.

```console
$ python3 -m venv .venv
$ source .venv/bin/activate
(.venv) $ pip install requests
(.venv) $ deactivate
$ uv init hello
$ cd hello
$ uv add requests
$ uv run main.py
```
The classic way, with venv and pip, then the same job with uv in four commands.

![Two project folders side by side on one computer. Project A has its own box marked .venv holding requests 2.31, and uses Python 3.12. Project B has its own box marked .venv holding requests 2.20, and uses Python 3.10. A version manager sits above both and switches the language version as you move between them. A note says each project keeps its own packages, so one cannot break the other.](https://learn.benibix.com/diagrams/dev-environments.svg)

### Example: Emma runs two Python projects

Emma's old project needs Python 3.10 and a 2021 version of a package. Her new one needs Python 3.12 and the latest version.

She sets up each one with uv, which installs both Python versions and keeps two sets of packages apart. Now, to switch projects, she just moves to the other folder.

**Words in this lesson:** [Virtual Environment](https://learn.benibix.com/term/development/virtual-environment), [Version Manager](https://learn.benibix.com/term/development/version-manager), [uv](https://learn.benibix.com/term/development/uv)

**Question:** Why did pip put my package in the wrong place?

**Answer:** The virtual environment was not turned on. pip installs into whichever Python is active. Turn the environment on first, and check for (.venv) at the start of the line.

---

Source: https://learn.benibix.com/learn/development-tools/virtual-environments-and-uv
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
