Python Virtual Environment: Activation & Deactivation

This guide provides quick commands to activate and deactivate Python virtual environments across different platforms.

🖥️ Windows (CMD)

python -m venv venv
venv\Scripts\activate
# To deactivate:
deactivate
    

🖥️ Windows (PowerShell)

python -m venv venv
venv\Scripts\Activate.ps1
# To deactivate:
deactivate
    

🐧 Linux / macOS

python3 -m venv venv
source venv/bin/activate
# To deactivate:
deactivate
    

🗑️ Deleting a Virtual Environment

Removing a virtual environment is straightforward—just delete its directory. Here's how to do it on each OS:

Windows

Remove-Item -Recurse -Force .env

Or manually delete the folder using File Explorer.

macOS / Linux

rm -rf venv

Make sure you're in the parent directory of the virtual environment before running this command.

⚠️ Note: This action is irreversible. Ensure you no longer need the environment before deleting it.

✅ Tip: Always activate your venv before installing packages to keep dependencies isolated.

📦 To install packages: pip install <package-name>