Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk4 min

Python Virtual Environments: Isolate Project Packages with venv

A Python virtual environment keeps a project’s packages separate from other projects. Learn how to create one with venv, install dependencies, and rebuild it safely.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A Python virtual environment gives a project its own place for installed packages and command-line tools, separate by default from other projects and the base Python installation’s packages. That separation lets different projects use different versions of a dependency without changing each other. For most projects that use third-party packages, create an environment with Python’s built-in venv module, install packages through that environment’s Python, and keep a separate record of dependencies so you can rebuild it.

What a Python virtual environment is—and what it isolates

A virtual environment is a directory created from an existing Python installation. It contains an environment-specific Python interpreter and its own location for installed packages and scripts. The Python Software Foundation describes venv environments as lightweight, with independent sets of packages in their “site” directories (Python 3.14.7 venv documentation).

As an Amazon Associate I earn from qualifying purchases.

It is not a separate operating system, nor does it install or select the base Python version for you. It isolates project packages by default: a package installed in one environment will not ordinarily be available to another environment or to the base installation. As a result, two projects can use different versions of the same library.

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

This is useful when one project depends on a particular library version and another needs a different one, or when you want to try an upgrade without changing packages used by other work. The Python Packaging Authority recommends using a virtual environment when working with third-party packages (Install packages in a virtual environment using pip and venv).

Create an environment for a project

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

python -m venv .venv

The command runs the venv module using the interpreter named python in that shell. If you have multiple Python versions installed, choose the intended interpreter explicitly. The Packaging User Guide gives these common alternatives:

  • Unix or macOS: python3 -m venv .venv
  • Windows: py -m venv .venv

Here, .venv is the environment directory name; using a project-local directory makes the setup easy to identify. The directory is created if needed and populated with environment files. If the command fails because venv is unavailable in your Python installation, consult the installation instructions for that Python distribution.

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

Activate it, or call its Python directly

Activation is optional. It is a shell convenience that puts the environment’s executable directory first on PATH, so commands such as python and pip resolve to the environment. The following commands cover bash or zsh on Unix/macOS and Windows Command Prompt:

# Unix/macOS with bash or zsh
source .venv/bin/activate

# Windows Command Prompt
.venvScriptsactivate

PowerShell, fish, and csh use different activation scripts; use the official venv reference for the command appropriate to your shell.

To verify which interpreter will run, use which python on Unix/macOS or where python in Windows Command Prompt. After activation, the path should point inside .venv. The environment variable VIRTUAL_ENV is set by activation, but it is not a reliable way to determine whether an environment is in use: direct interpreter calls work without activation.

You can bypass activation and invoke the environment’s interpreter by its path:

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

This direct form is useful in scripts and automation because it makes the interpreter choice explicit. To leave an activated environment, run deactivate or close the shell.

Install packages into the environment’s Python

With the environment active, install a package using:

python -m pip install package-name

Using python -m pip ties the installer to the Python interpreter named python, reducing the chance that a standalone pip command installs into a different Python installation. If you are not activating the environment, use its interpreter directly:

.venv/bin/python -m pip install package-name

On Windows, use .venvScriptspython.exe -m pip install package-name. Replace package-name with the package you need. By default, packages installed this way belong to this environment, not to every Python project on the computer.

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.

Record dependencies so you can rebuild the setup

The environment directory is disposable; the project’s dependency declaration is what lets you recreate its package setup. The Python Packaging Authority documents requirements files for recording and reinstalling packages in its Installing Packages tutorial. A common workflow is to keep a requirements file with the project and install from it in a newly created environment:

python -m pip install -r requirements.txt

Keep the dependency record under version control, but do not commit .venv. If the project is moved or checked out at a new path, create a fresh environment there and reinstall the recorded dependencies. Environments are generally not portable: installed scripts can contain absolute paths to the environment’s interpreter, so moving the directory may leave them pointing to the old location.

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

What virtual environments do not do

  • They do not choose a Python version. The environment is built from the interpreter that runs python -m venv; install or select the desired base Python separately.
  • They do not necessarily include every packaging tool. The Python 3.14.7 documentation notes that setuptools has not been a core venv dependency starting with Python 3.12, so do not assume a new environment contains it.
  • They are not always isolated from base packages. The default is isolation, but the --system-site-packages option changes that behavior.
  • They do not require activation. Directly calling the environment interpreter uses it without changing the shell’s command lookup.

When a basic venv is enough

For a single project, venv plus pip and a dependency record is usually a straightforward way to separate packages and recreate the setup. The Packaging User Guide also notes that managing many environments directly can become tedious and points readers toward higher-level tools (Installing Packages tutorial). That is an optional next step for more complex workflows, not a prerequisite for using a virtual environment.

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.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.