Skip to content

Instantly share code, notes, and snippets.

@grantpullen
Created March 4, 2025 14:42
Show Gist options
  • Save grantpullen/fc9dde93ae6ec5b729bd6633b5180d7c to your computer and use it in GitHub Desktop.
Save grantpullen/fc9dde93ae6ec5b729bd6633b5180d7c to your computer and use it in GitHub Desktop.
python venv

Setting Up a Python Virtual Environment (venv) on a Mac

  1. Install Python (if not already installed)

Check if Python is installed:

python3 --version

If Python is not installed, download and install it from python.org.

  1. Create a Virtual Environment

Navigate to the directory where you want to create the virtual environment and run:

python3 -m venv myenv

Replace myenv with your desired virtual environment name.

  1. Activate the Virtual Environment
source myenv/bin/activate

Once activated, your terminal prompt will change, showing (myenv) before the command line.

  1. Deactivate the Virtual Environment

To exit the virtual environment, use:

deactivate
  1. Best practice location for Virtual Environments

Virtual environments are typically stored in your project directories. exmple init and activate below:

cd my_project
python3 -m venv venv
source venv/bin/activate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment