🐍 How to Set Up a Python Virtual Environment (venv) on Windows, MacOS, and Linux (For Absolute Beginners)


Goal: After this, you’ll know how to create an isolated space on your computer to safely install Python packages — without breaking your system.
➡️ What’s a Virtual Environment?
Setting up a virtual environment might sound fancy, but it’s just a way to keep your Python projects neat and tidy — like having your own little workspace where you can install packages without messing up your whole system.
Here’s how to do it on Windows, MacOS, and Linux — step-by-step, no confusing stuff.
Think of a venv like a sandbox. It keeps all the Python packages for one project separate from all the other projects or your main Python install. That way, you don’t get version headaches or conflicts.
❓First, let’s check if python is ready to go
Before anything, check if Python is installed and ready.
Open your terminal (Command Prompt on Windows, Terminal on Mac/Linux), and type:
python --version
Or if that doesn’t work ad a 3 after python:
python3 --version
If you see a version number like Python 3.x.x
, you’re good. If not, go grab Python from
👉 https://www.python.org/downloads/
IMPORTANT: Add Python to PATH on Windows when installing.
Steps on All Operating Systems
✅ First: Pick or Create a Project Folder
Note: You can totally do this part in File Explorer — no need to wrestle with the terminal just to create or move files. But heads up: you’ll still need a command line window to actually start your app.
For example:
Documents/my-python-project
Navigate there:
cd Documents/my-python-project
👉Again: You can totally do that part in File Explorer, no need to complicate it.
✅ Next: Create the Virtual Environment
Run this command:
python -m venv venv
Or if python
doesn’t work:
python3 -m venv venv
-m venv
says: "use the venv tool"The second
venv
is the name of the folder that will hold the virtual environment files.
You can name it whatever you want, butvenv
is common.
✅ 3rd step: Activate the Virtual Environment
Here’s where the OS-specific part comes in:
OS | Command |
Windows (CMD): | venv\Scripts\activate.bat |
Windows (PowerShell): | .\venv\Scripts\Activate.ps1 |
MacOS / Linux: | source venv/bin/activate |
👉 Remember: The PowerShell command requires the leading “ . “ in order to tell PowerShell to run a script in the current directory.
✅ If it works: You’ll see the environment name appear at the start of your prompt:
(venv) <---- like that
✅ Fourth: Install Packages Safely
While the venv is activated, install whatever you want, like:
pip install flask
Everything you install here stays inside the venv, not globally.
✅ Fifth: Check What’s Installed
pip list
✅ Sixth: Deactivate When Done
Simply type:
deactivate
You’re back to normal. The venv is still there — you just reactivate it next time.
Summary Cheat Sheet
Task | Windows | MacOS / Linux |
Create venv | python -m venv venv | python3 -m venv venv |
Activate | CMD: venv\Scripts\activate.bat or PowerShell: .\venv\Scripts\Activate.ps1 | source venv/bin/activate |
Deactivate | deactivate | deactivate |
Bonus Tip: Deleting a venv
To remove the whole environment:
rm -rf venv
On Windows, manually delete the venv
folder.
Troubleshooting Common Problems
❌ Command not found?
Trypython3
instead ofpython
.❌ Permission denied on Mac/Linux?
chmod +x venv/bin/activate
- ❌ Windows PowerShell error (Execution Policy)?
Run PowerShell as Administrator:
Set-ExecutionPolicy RemoteSigned
Recap…
…of what you should have learned:
Why virtual environments exist
How to make them on any OS
How to activate, use, and deactivate them
How to clean up
Now you can work on Python projects without messing up your system or other projects.
Subscribe to my newsletter
Read articles from Matthew Hard directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Matthew Hard
Matthew Hard
I'm Matthew, a cybersecurity enthusiast, programmer, and networking specialist. With a lifelong passion for technology, I have dedicated my career to the world of cybersecurity, constantly expanding my knowledge and honing my skills. From a young age, I found myself captivated by the intricate workings of computers and networks. This fascination led me to pursue in-depth studies in the fields of networking and cybersecurity, where I delved deep into the fundamental principles and best practices. Join me on this exciting journey as we explore the multifaceted world of technology together. Whether you're a beginner or a seasoned professional, I am here to share my knowledge, discuss the latest trends, and engage in insightful discussions. Together, let's embrace the ever-changing world of tech and navigate the complexities of cybersecurity with confidence and expertise.