Python Virtual Environments on Windows: A Complete Guide


devops

If you’re starting multiple Python projects, you will quickly run into a problem: one project needs Version 1.0 of a library, while another needs Version 2.0. If you install everything globally, you’ll end up with a broken mess.

This is where Virtual Environments (venv) come in. They allow you to create isolated “bubbles” for each project, ensuring that your dependencies never clash. In this guide, we’ll walk through exactly how to use them on Windows.


1. Creating the Environment

Open your Command Prompt or PowerShell and navigate to your project folder. Run the following command:

# General syntax: python -m venv [folder_name]
python -m venv .venv

Note: .venv is the standard name for the folder, but you can name it whatever you like (e.g., myenv).


2. Activating the Environment

Creating the folder isn’t enough; you have to tell your terminal to start using it. The activation command depends on whether you are using the old Command Prompt (CMD) or the modern PowerShell.

For Command Prompt (CMD):

.venv\Scripts\activate

For PowerShell:

.venv\Scripts\Activate.ps1

How do I know it worked? You should see the name of your environment in parentheses at the start of your command prompt line, like this: (.venv) C:\Users\Projects\MyProject>


3. Installing Packages

Once activated, any package you install using pip will be contained entirely within that folder.

pip install flask

If you look inside .venv\Lib\site-packages, you will see Flask and its dependencies sitting right there!


4. Deactivating

When you’re done working, or if you want to switch to another project, simply type:

deactivate

Your prompt will return to normal, and you will be back in your global Python environment.


Common Issues on Windows

“Running Scripts is Disabled” (PowerShell)

If you get a red error in PowerShell saying “Scripts cannot be loaded,” it’s because Windows blocks third-party scripts by default. You can fix this by running this command once as an Administrator:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Summary Checklist

  1. Create: python -m venv .venv
  2. Activate: .venv\Scripts\activate
  3. Use: pip install ...
  4. Finish: deactivate

Mastering virtual environments is the first step toward becoming a professional Python developer. It keeps your computer clean and your projects reproducible!

Written by

Abdur-Rahmaan Janhangeer

Chef

Python author of 7+ years having worked for Python companies around the world

Suggested Posts

Python: Running makefile on windows using git mingw bash

Linux owners configure makefiles so as to have easy commands to perform operations such as make depe...

Read article

Installing pipx on Mint and Ubuntu

pipx allows you to use python projects on the commandline without using a virtual environment each t...

Read article

Python EFL: Building Custom Elementary Widgets (2026)

Want to create unique UI components tailored to your app’s needs? This Python EFL tutorial teaches y...

Read article
Free Flask Course