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 DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk5 min

Python venv Keeps Project Packages Separate—Here’s How

Use Python’s built-in venv to isolate project packages, install them with the right interpreter, and recreate the environment when needed.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A Python virtual environment gives each project its own set of installed packages, so one project’s dependencies are less likely to interfere with another’s. For a first setup, use Python’s built-in venv: create a project-local .venv, activate it if you want shell convenience, install packages through that environment’s Python, and record dependencies so you can rebuild it later.

What a Python virtual environment does

A virtual environment is an isolated Python installation context for a project. Packages installed there are kept separate from the base Python installation and other environments by default. That matters when projects need different versions of the same library, or when you want to avoid adding project-specific packages to the Python installation used elsewhere.

As an Amazon Associate I earn from qualifying purchases.

Python includes venv in its standard library, so you can start without installing a separate environment tool. The Python documentation describes venv as the standard way to create virtual environments: Python 3.14.8 venv documentation.

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

Create an environment in your project

Open a terminal in the project directory and run:

python -m venv .venv

The command runs venv using the Python interpreter selected by python and creates the environment in a directory named .venv. That name is a common convention; the directory can have another name if your project requires it. To create an environment with a particular Python version, run the command with that version’s interpreter or launcher instead. The directory includes the environment’s Python executable and supporting package and script directories.

If python is not recognized or selects the wrong installation, use the Python command appropriate to your platform and installation. On Windows, for example, the Python launcher may let you select a version with a command such as py -3.14 -m venv .venv; use the version you actually have installed. Python’s tutorial describes creating environments with the interpreter command used on the system: Python tutorial: Virtual Environments and Packages.

By default, venv creates an isolated environment and bootstraps pip. Avoid --system-site-packages for a first environment: that option allows it to see packages installed in the base Python and changes the default isolation. The setuptools package is no longer a core venv dependency starting with Python 3.12, so do not assume every new environment includes it.

Activate it—or use its Python directly

Activation adjusts the current shell so that commands such as python and installed scripts resolve to the environment first. The activation command depends on the operating system and shell:

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.
Shell Activation command from the project directory
bash or a similar Unix-like shell source .venv/bin/activate
Windows Command Prompt .venvScriptsactivate.bat
Windows PowerShell .venvScriptsActivate.ps1

Other shells can have different activation scripts. Unix-like environments use a bin directory; Windows uses Scripts. When activation works, the prompt commonly displays the environment name, but the prompt is not the definitive check. Run:

python -c "import sys; print(sys.executable)"

Confirm that the printed path points inside your project’s .venv directory. This is a practical way to check which interpreter the shell will use.

Activation is optional

You can run the environment’s Python directly without activating it. The Python documentation states: “You don’t specifically need to activate a virtual environment, as you can just specify the full path to that environment’s Python interpreter when invoking Python.” See the venv documentation.

For example, from the project directory, the direct interpreter paths are:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
# Unix-like systems
.venv/bin/python -m pip install requests

# Windows
.venvScriptspython.exe -m pip install requests

Activation is convenient when you will run several commands in the same shell. An explicit interpreter path is more deliberate and avoids relying on shell activation; both approaches use the same environment.

If PowerShell blocks activation

PowerShell may refuse to run the activation script because of its execution policy. If you choose to change the policy, the Python documentation gives this per-user command:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Follow your organization’s and system’s security rules before changing execution policy. You can leave the policy unchanged and use the environment’s full Python path instead.

Install packages into the selected environment

After activation, install a package with:

python -m pip install requests

Use python -m pip rather than relying on a bare pip command: it runs pip through the Python currently selected by the shell, reducing the chance that the package goes into a different installation. To inspect packages installed in that environment, run:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
python -m pip list

The Python Packaging Authority’s guide walks through installing packages with pip and venv: Install packages in a virtual environment using pip and venv. That guide describes a supported-version scope of Python 3.8 and higher and assumes an official Python distribution; if you use an operating-system package manager, you may need to install Python separately.

Record dependencies so the environment can be rebuilt

A virtual environment directory is not a portable project dependency record. For a basic freeze-based workflow, save the installed package list in the project:

python -m pip freeze > requirements.txt

After creating a fresh environment, install the recorded packages into it with:

python -m pip install -r requirements.txt

Keep requirements.txt with the project when this workflow suits it. It records package requirements for installation; it does not turn the existing .venv directory into something safe to copy or relocate. The Python documentation recommends having a simple way to recreate an environment, including installing packages from a requirements file: venv documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Deactivate, reset, or troubleshoot the environment

Leave an activated environment

In the activated shell, run:

deactivate

This returns that shell to its prior command lookup. It does not delete the environment or its packages.

Rebuild a damaged or outdated environment

  1. Deactivate the environment if it is active.

  2. Remove the project’s .venv directory using your operating system’s file manager or a suitable command.

  3. Recreate it with python -m venv .venv, using the intended Python interpreter.

  4. Activate the new environment if desired, then run python -m pip install -r requirements.txt if the project has that file.

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

Do not move or copy an environment directory as a way to share it. Installed scripts can contain absolute paths to that environment’s interpreter, so relocation can break them. Recreate the environment in its intended location instead.

When the wrong Python or packages appear

  • Run python -c "import sys; print(sys.executable)" and check whether the path is inside .venv.

  • Use python -m pip for package operations so pip is tied to the selected interpreter.

  • If a custom PYTHONPATH is interfering with imports, unset or correct it; activation changes shell command lookup through PATH, not PYTHONPATH.

    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.
  • If shell activation is inconvenient or blocked, call .venv/bin/python on Unix-like systems or .venvScriptspython.exe on Windows directly.

When to move beyond built-in venv

For learning Python project dependencies or managing a straightforward project-local environment, start with venv and a requirements file when a package record is useful. A separately installed alternative such as virtualenv may be appropriate when you need its broader Python-version support. Higher-level environment managers can make sense when you want automatic environment creation or broader dependency-management features, but they are not prerequisites for the basic isolated workflow.

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.

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
Crashes, No Sound, or Screen Glitches?Free driver scan

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.