# 🐍 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

1. Before anything, check if Python is installed and ready.
    
    Open your terminal (Command Prompt on Windows, Terminal on Mac/Linux), and type:
    

```powershell
python --version
```

Or if that doesn’t work ad a 3 after python:

```powershell
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/](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:

```powershell
Documents/my-python-project
```

Navigate there:

```powershell
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:

```powershell
python -m venv venv
```

Or if `python` doesn’t work:

```powershell
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, but `venv` 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.ps](http://Activate.ps)1 |
| **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:

```powershell
(venv) <---- like that
```

---

### ✅ Fourth: Install Packages Safely

While the venv is activated, install whatever you want, like:

```powershell
pip install flask
```

Everything you install here **stays inside the venv**, not globally.

---

### ✅ Fifth: Check What’s Installed

```powershell
pip list
```

---

### ✅ Sixth: Deactivate When Done

Simply type:

```powershell
deactivate
```

You’re back to normal. The venv is still there — you just reactivate it next time.

---

## S**ummary 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:

```powershell
rm -rf venv
```

On Windows, manually delete the `venv` folder.

---

## **Troubleshooting Common Problems**

1. ❌ *Command not found?*  
    Try `python3` instead of `python`.
    
2. ❌ *Permission denied on Mac/Linux?*
    

```powershell
chmod +x venv/bin/activate
```

3. ❌ *Windows PowerShell error (Execution Policy)?*  
    Run PowerShell as Administrator:
    

```powershell
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.**
