Skip to the content.

Here’s an guide that includes instructions for installing the venv module and creating virtual environments on Mac, Linux, and Windows:

Prerequisites:


Step 1: Install venv (if not already installed)

Mac & Linux:

Windows:


Step 2: Create a Virtual Environment

Mac & Linux:

  1. Navigate to the desired directory where you want to create your virtual environment:

    cd /path/to/your/project
    
  2. Create the virtual environment using venv:

    python3 -m venv venv_name
    

    Replace venv_name with the name you want for your virtual environment.

  3. Activate the virtual environment:

    source venv_name/bin/activate
    
  4. Deactivate the virtual environment when you're done:

    deactivate
    

Windows (Command Prompt):

  1. Navigate to the desired directory where you want to create your virtual environment:

    cd path\to\your\project
    
  2. Create the virtual environment using venv:

    python -m venv venv_name
    
  3. Activate the virtual environment:

    venv_name\Scripts\activate
    
  4. Deactivate the virtual environment when you're done:

    deactivate
    

Windows (PowerShell):

  1. Navigate to the desired directory where you want to create your virtual environment:

    cd path\to\your\project
    
  2. Create the virtual environment using venv:

    python -m venv venv_name
    
  3. Activate the virtual environment:

    .\venv_name\Scripts\Activate
    

    If activation fails, you might need to change the execution policy:

    Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
    
  4. Deactivate the virtual environment when you're done:

    deactivate
    

Notes: