Create a Python Virtual Environment on Windows (py -m venv)

Isolate each project's packages in a .venv folder and activate it in PowerShell.

WindowspythondeveloperpowershellLow risk
Run `py -m venv .venv` in your project folder, then ` .venv\Scripts\Activate.ps1` to activate it.

01Command

Command
$ py -m venv .venv ; .venv\Scripts\Activate.ps1

02What it does

The venv module creates a self-contained folder with its own Python interpreter and site-packages, so pip installs stay local to the project. The py launcher picks your default Python 3 installation. Once activated, your prompt shows (.venv) and `pip install` affects only this environment; deactivate with the `deactivate` command.

03Risk

RiskLow risk
RequirementsPython installed (py launcher ships with python.org installers); for Activate.ps1, allow scripts via Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser.
!Warning: PowerShell blocks Activate.ps1 by default — allow signed local scripts once with Set-ExecutionPolicy RemoteSigned -Scope CurrentUser.

04Undo

Undo
$ Remove-Item -Recurse -Force .venv

05Sources

Last verified: 2026-09-19 · Category: Developer

06Related solutions