Python VENV Virtual Environment Tutorial on Windows for Absolute Beginners
by xanthium-enterprises in Circuits > Computers
223 Views, 0 Favorites, 0 Comments
Python VENV Virtual Environment Tutorial on Windows for Absolute Beginners
If you’re just getting started with Python, you’ve probably heard about virtual environments,but what exactly are they, and why should you care?
With the recent changes in Python,It is recommended to create a self contained local environment to install the packages you want for your software project instead of cluttering up the System Python Environment.The packages are installed locally in a specific directory inside your file system separate from the system Python Installation and multiple packages can coexist without conflicts.
Here We will be using the VENV module to create a Python Virtual Environment on a Windows 11 OS
In this Instructable, you’ll learn
- What a Python VENV virtual environment is and why it’s important
- How to create a Python VENV on Windows step-by-step
- How to activate, use, and deactivate your venv environment on Windows 11 or 10
- Where to find your venv’s files and structure
- How to solve the commonly encountered issues like PowerShell Execution Policy error
By the end, you’ll have a fully working virtual environment on your Windows machine and a solid understanding of how to use it for any Python project.
More information can be found below.
Supplies
Before getting started, make sure you have the following tools and software ready:
1. A Windows Computer
Any modern version of Windows (Windows 10 or 11 recommended).Administrator access may be needed for installing Python.
2. Python (Version 3.6 or newer)
Download and install the latest version of Python from the official website
3. Command Prompt or PowerShell
These come pre-installed with Windows and will be used to create and activate your virtual environment.
What Is a Virtual Environment & Why We Need It
In Python, a virtual environment is an isolated workspace that allows you to manage project-specific dependencies separately from your system-wide Python installation. Instead of installing all Python packages globally (where they could interfere with other projects), a virtual environment keeps everything contained within its own directory.
What is a venv Module
Python comes with a built-in module called venv, which makes it simple to create and manage these isolated environments. When you use venv to create a new environment, Python automatically sets up a dedicated folder that includes:
- A copy of the Python interpreter, specific to that environment.
- A local site-packages directory, where all project-specific libraries are stored.
- Scripts to activate and deactivate the environment easily.
Here is a simplified block diagram of a VENV module

Each virtual environment functions independently , meaning you can install, upgrade, or remove packages without affecting other projects or the system’s global Python installation.
Why we need it
Using a venv offers several key benefits. It keeps your projects organized by isolating dependencies, prevents your global Python installation from becoming cluttered with unnecessary packages, and allows you to easily reproduce environments across different systems using a requirements.txt file.
Additionally, it provides a safe space to experiment with new libraries or package versions without risking your main Python setup.
Creating the Venv on Windows 11
In this section, we will go through the process of setting up a Python venv on Windows 11. Windows do not come with Python Preinstalled So you may need to install it on your Windows 10 or 11 PC.
Installing Python
Before creating a virtual environment, you need to make sure Python is installed on your system. Open Command Prompt or PowerShell and run
If Python is installed, you will see its version number. If you get an error like " python' is not recognized as an internal or external command ", it means Python is not installed.
If Python is not installed,Please install it from python.org website
Run the installer and make sure to check the box “Add Python to PATH” before clicking install.
This ensures you can run Python commands from the Command Prompt or PowerShell without any additional setup.
Creating a Python VENV Environment
Now, let’s create a Python venv virtual environment on your Windows 11 PC for developing code.
First, create a main folder to store your project files and the virtual environment. Inside this folder, create a separate folder for your Python source code:
Here,Windows-Venv-Project will hold both your virtual environment and your project files.
Inside the Windows-Venv-Project folder, run the following command to create a virtual environment named venv
This command will generate a folder called venv inside Windows-Venv-Project. The venv folder contains all the necessary Python executables and scripts required to run and activate the virtual environment.
VENV Folder Structure Overview
After creating the virtual environment, your project directory should look like this (only the relevant parts are shown)

This structure keeps your project organized, with a dedicated space for your code (src) and an isolated environment (venv) for dependencies and Python executables.
Understanding the Folder Structure of Python VENV on Windows
Here is a simplified directory structure of the Python venv virtual environment on Windows 11.

As you can see, the Windows venv environment contains fewer directories compared to a Linux venv, making it relatively straightforward to navigate.
The main folder typically includes the Scripts directory, which holds the activation scripts (activate.bat, Activate.ps1) and Python executables, and the Lib directory, which contains installed packages for the virtual environment.
The virtual environment directory is typically organized into three main components as shown in the above image, Scripts, Lib, and Include.
Scripts directory is the heart of the environment for running and managing Python. It contains activation scripts for different command-line shells, such as PowerShell (Activate.ps1) and Command Prompt (activate.bat). These scripts configure your shell to use the Python interpreter and installed packages inside the virtual environment rather than the global Python installation.
Lib directory is where all the Python standard libraries and third-party packages installed via pip reside. When you install a new package while the virtual environment is active, it is added to this folder, making it available only within that particular environment.
Include directory contains C headers that are required for compiling Python extensions or building certain packages that include native code. While beginners may not interact with this folder directly, it is essential for ensuring that Python packages which require compilation can be installed correctly within the virtual environment.

Together, these three directories provides everything needed to run, manage, and develop Python projects in isolation, keeping dependencies organized, safe, and reproducible across different machines.
How to Activate Python VENV Environment on Windows
Once you have created a Python virtual environment using the venv module, the next step is to activate it so that Python and pip commands use the environment’s isolated setup rather than the system-wide installation.
Activation is slightly different depending on whether you are using Command Prompt or PowerShell.
To activate your virtual environment in Command Prompt
PowerShell uses a different script for activation. To activate the environment
After activation, you should see the virtual environment’s name ( (venv)) appear at the beginning of the command line prompt. This indicates that all Python and pip commands will now be executed within the virtual environment.
If you encounter the error “Activate.ps1 cannot be loaded because running scripts is disabled on this system”, it’s due to PowerShell’s execution policy. The next section teaches you how to solve the error.
Fixing PowerShell Execution Policy Errors When Activating Venv
When you try to activate a Python virtual environment in PowerShell using Activate.ps1, you may encounter an error message stating that the script “cannot be loaded because running scripts is disabled on this system.”

This happens because Windows PowerShell has an execution policy that restricts running scripts by default for security reasons.
The default policy, typically Restricted, prevents any PowerShell scripts, including the Activate.ps1 script generated by Python’s venv module from executing.
To resolve this issue, you need to temporarily or permanently change the execution policy to allow scripts to run.
This can be done by opening PowerShell as an administrator and running a command like Set-ExecutionPolicy RemoteSigned, which permits running local scripts while still protecting you from potentially harmful scripts downloaded from the internet.
After changing the execution policy, you will be able to successfully activate your virtual environment using the Activate.ps1 script.
How to DeActivate Python VENV on Windows
Once you have finished working in a Python virtual environment, it’s important to deactivate it to return to your system’s global Python installation.
Deactivating ensures that any Python commands or package installations you run afterward will no longer affect the virtual environment.
Deactivating a virtual environment is simple and works the same way in both Command Prompt and PowerShell
After running this command, the (venv) prefix will disappear from the prompt, indicating that you have returned to the system-wide Python environment.
Adding Packages to Your Python VENV Environment
One of the key benefits of using a Python virtual environment (venv) is that you can install project-specific packages without affecting your system-wide Python installation.
We will place our Python code inside the src folder within the Windows-Venv-Project directory. For this project, we will install the pyserial package, which allows us to open and close serial ports directly from Python. Unlike Linux, the pyserial library is not included by default on Windows, so it must be installed manually.
Before running the pip install command, make sure your virtual environment is activated, so the package is installed within the venv folder and does not affect your system-wide Python installation. Activation ensures that all dependencies remain isolated and specific to your project.
Now we will create a simple python script named my_python_program.py inside the src folder
After activating the python environment. you can run the code using the below command