Programming & syntax · reviewed in July 2026
Virtual environment
A virtual environment is an isolated Python installation with its own set of packages, independent of the system-wide installation. It lets different projects use different versions of the same library without conflicting with each other.
python -m venv .venv source .venv/bin/activate pip install -r requirements.txt
Frequently asked questions
Why not just install everything globally?
Because two projects can need different, incompatible versions of the same library; installing everything globally eventually breaks one of them.
How do you create a virtual environment in Python?
With the standard venv module (python -m venv .venv), or with tools like uv or Poetry, which also manage the project's dependencies.
Does the virtual environment get committed to the code repository?
No. The packages a project needs are declared in a file (like pyproject.toml or requirements.txt), and each person recreates their own local environment from that file.