Skip to content

Python Virtual Environment On Windows

  • by

First, I installed Windows Terminal and Python 3.7 from the Microsoft Store

Created a directory for the virtual environments

PS> mkdir venv

Create a virtual environment called “main”

PS> python -m venv .\venv\main

Activate a virtual environment

PS> .\venv\main\Scripts\Activate.ps1

Exit the virtual environment

(main) PS> deactivate

Enabling scripts on Windows

If you get this error

.\venv\main\Scripts\Activate.ps1 : File C:\Users\benjo\venv\main\Scripts\Activate.ps1 cannot be loaded because running scripts is disabled on this system.

Then open a new terminal as admin and run

PS> set-executionpolicy remotesigned

Then try to activate again

PS> .\venv\main\Scripts\Activate.ps1
(main) PS C:\Users\benjo>

Leave a Reply

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