A virtual environment is an isolated workspace for your Python projects.
It helps you manage dependencies for each project separately — so your global Python setup stays clean.
Step 1: Open Command Prompt or PowerShell
Navigate to your project folder using:
cd <project_directory>
(Replace <project_directory> with your actual project path, for example:)
cd C:\Users\hp\projects\zerodapi
Step 2: Create a Virtual Environment
Run this command:
python -m venv venv
✅ This will create a folder named venv inside your project directory, containing the isolated Python environment.
Step 3: Activate the Virtual Environment
Now activate it:
venv\Scripts\activate
Once activated, you’ll notice your terminal prompt changes to something like this:
(venv) PS C:\Users\hp\projects\apiproject>
This means your virtual environment is active!
Any Python packages you install now will only apply inside this project.
Step 4: Fix “UnauthorizedAccess” or “PSSecurityException” Error
If you see an error like this:
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
It means PowerShell is blocking script execution.
To fix it, run this command (once):
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
Then try activating again:
venv\Scripts\activate
Step 5: Deactivate When You’re Done
When you finish working in the environment, simply deactivate it:
deactivate