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.
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.
#1 Best Overall
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.
| 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.
Rank #2
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:
# 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:
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitchespython -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.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Deactivate, 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
-
Deactivate the environment if it is active.
-
Remove the project’s
.venvdirectory using your operating system’s file manager or a suitable command. -
Recreate it with
python -m venv .venv, using the intended Python interpreter. -
Activate the new environment if desired, then run
python -m pip install -r requirements.txtif the project has that file.Recommended: Fix Windows Errors and Clear Junk Files in Minutes - Free Scan →Recommended: Crashes or Glitches? A Free Driver Scan Usually Finds the Culprit →Recommended: PC Feels Slow? A Free Scan Shows What's Dragging Windows Down →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.
Best Value
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 pipfor package operations so pip is tied to the selected interpreter. -
If a custom
PYTHONPATHis interfering with imports, unset or correct it; activation changes shell command lookup throughPATH, notPYTHONPATH.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/pythonon Unix-like systems or.venvScriptspython.exeon 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.
Quick Recap
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.




