Back to Blog

Virtual Environment for Mac vs Windows

By Yanka Sikder · August 15, 2024

What is a Virtual Environment?

A virtual environment is a tool that helps to keep dependencies required by different projects separate by creating isolated Python environments for them. This means each project can have its own dependencies regardless of what dependencies every other project has.

Mac Commands

# Create virtual environment

python -m venv env

# Activate

source env/bin/activate

Windows Commands

# Create virtual environment

python -m venv env

# Activate

cd env

cd Scripts

activate

Useful Tips

  • Use pip freeze > requirements.txt to save your installed libraries.
  • Use pip install -r requirements.txt to reinstall libraries from the file.
  • Add env/ to your .gitignore to prevent uploading the virtual environment to GitHub.