Skip to content

Instantly share code, notes, and snippets.

@ByteJoseph
Created June 12, 2024 02:43
Show Gist options
  • Save ByteJoseph/252057b528d156b1e4d2c54470775a37 to your computer and use it in GitHub Desktop.
Save ByteJoseph/252057b528d156b1e4d2c54470775a37 to your computer and use it in GitHub Desktop.
Creating and activating a Python virtual environment on Windows

Creating and Activating a Python Virtual Environment on Windows

Windows Logo

Step-by-Step Guide

1. Open Command Prompt or PowerShell

Tip: You can find Command Prompt by searching for "cmd" or PowerShell by searching for "powershell" in the Start menu.

2. Create the Virtual Environment

In Command Prompt or PowerShell, type the following command and press Enter:

python -m venv env

3. Activate the Virtual Environment

Command Prompt

If you are using Command Prompt, type the following command and press Enter:

env\Scripts\activate

OR

PowerShell

If you are using PowerShell, the steps are a bit different. By default, PowerShell may prevent script execution. To temporarily allow script execution, type the following command and press Enter:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process

Then, activate the virtual environment with:

Warning: The activation command differs between Command Prompt and PowerShell.

.\env\Scripts\Activate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment