Skip to content
BENIBIX Learn

Virtual Environment

Development🛠️ Editors & ToolsDevelopment Environments

Also known as venv, Python Virtual Environment, virtualenv, .venv

A folder for one project. It holds the Python code that project needs.

Think of it like

It is like giving each child their own toy box. One child's mess never ends up in another's box.

Example

Emma's old project needs an old version of a package, and her new one needs the latest. Each gets its own .venv, and both work.

Why it matters

Without one, all your projects share the same packages. Then an update for one project can break another.

Definition

A virtual environment is a folder that holds the Python packages for one project. When it is on, what you install goes into that folder only. So two projects can use two versions of the same package, and both still work. You make one with python3 -m venv .venv, then turn it on before you install anything.

Example code

console
$ python3 -m venv .venv
$ source .venv/bin/activate
(.venv) $ pip install requests
Make the folder, turn it on, then install. The prompt shows which one is on.
Two projects, each with its own .venv and its own package versions.

Common mistake

Forgetting to turn it on, so pip installs into the main Python instead. Look for (.venv) at the start of the prompt.

Key takeaways

  1. 1
    One per project. Each project gets its own folder.
  2. 2
    Turn it on first. Then installs go into that folder.
  3. 3
    Throw it away freely. Do not commit it; rebuild it any time.

Compare

Learn it properly