Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

A Python virtual environment gives a project its own place to install packages, so one project can use a dependency version without changing what another project or your base Python installation uses. Create one with python -m venv .venv, install packages through its Python interpreter, and keep a separate record of the dependencies so you can rebuild it.

What a Python virtual environment is

A virtual environment is a directory created from an existing Python installation. It includes an environment-specific interpreter and a place for that environment’s installed packages and scripts. It is not a separate operating system or a complete, independent Python installation.

The Python Software Foundation describes venv as supporting “lightweight ‘virtual environments’, each with their own independent set of Python packages installed in their ‘site’ directories” (Python 3.14.7 venv documentation). By default, packages in an environment are isolated from other environments and from the base installation’s site-packages. That lets two projects use different versions of the same library without overwriting each other’s packages.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Why use one for each project

Without an environment, packages installed for one project may affect other Python work that uses the same installation. A project-specific environment makes it clearer where a package belongs and reduces dependency conflicts. The Python Packaging Authority recommends using one when working with third-party packages (Install packages in a virtual environment using pip and venv).

  • Separate dependencies: install a project’s packages without changing the packages used by another project.
  • More predictable commands: once the environment is active, python and pip resolve to that environment.
  • Rebuildable setup: record dependencies separately from the environment directory, then install them again when recreating the environment.

Create a project environment

Open a terminal in the project directory and run the command for the Python interpreter you intend to use as the base:

python -m venv .venv

The command runs that interpreter’s built-in venv module and creates the environment in a local directory named .venv. If your system distinguishes between Python versions, choose the intended interpreter explicitly. The Packaging User Guide shows python3 -m venv .venv on Unix-like systems and py -m venv .venv on Windows (Packaging User Guide setup instructions).

Creating the environment does not install or select a different base Python version. It uses the interpreter that runs the command, so verify that this is the version your project needs.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Activate it, or invoke its Python directly

Activation is a shell convenience: it puts the environment’s executable directory first on PATH, so commands such as python and pip point to the environment. The activation command depends on your shell.

bash or zsh on Unix or macOS

source .venv/bin/activate

Windows Command Prompt

.venvScriptsactivate

PowerShell, fish, and csh use different scripts. Consult the official venv reference for the command that matches your shell.

To check which interpreter a shell will run, use which python on Unix or macOS, or where python in Windows Command Prompt. Run deactivate to leave an activated environment, or close the shell.

You do not have to activate the environment. You can call its interpreter directly, which is useful in scripts and automation where you want the interpreter path to be explicit:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • POSIX: .venv/bin/python
  • Windows: .venvScriptspython.exe

VIRTUAL_ENV is set when an environment is activated, but it is not a definitive way to detect an environment: direct interpreter invocation works without activation.

Install and record project dependencies

With the environment active, install a package using python -m pip. This pairs pip with the Python interpreter that will use the package:

python -m pip install package-name

For a reproducible setup, record the project’s dependencies in a requirements file rather than relying on the environment directory itself. The Packaging User Guide covers requirements files and reinstalling packages (Installing Packages). When you need a fresh environment, create it again and install the recorded dependencies into it.

Keep the environment disposable

Do not commit .venv to Git or treat it as a portable project artifact. Environment files can include paths tied to their original location, including paths used by installed scripts. If you move the project, recreate the environment at the new location and reinstall its recorded dependencies.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

By default, an environment does not use the base installation’s site-packages. The --system-site-packages option changes that isolation behavior; use it only when you deliberately want the environment to see packages installed for the base Python.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When a basic venv workflow may not be enough

venv is part of Python’s standard library and is sufficient for creating an isolated environment and installing packages with pip. If you need to manage many environments or a more involved dependency workflow, the Python Packaging Authority notes that handling environments directly can become tedious and points readers toward higher-level tools (Installing Packages). That is an optional next step, not a requirement for a basic project setup.

Environment contents can also vary by Python version. For example, the Python 3.14.7 venv documentation notes that setuptools has not been a core venv dependency since Python 3.12. Do not assume a newly created environment includes it; install it if your project requires it.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.