Skip to content

Latest commit

 

History

History
127 lines (97 loc) · 2.9 KB

File metadata and controls

127 lines (97 loc) · 2.9 KB

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

Prerequisites:

  • Python 3.x installed on your system. To check, run:
    python3 --version
    or
    python --version

Step 1: Install venv (if not already installed)

Mac & Linux:

  • If you are using a Linux distribution or macOS, you may need to install venv using your package manager:

    For Debian/Ubuntu:

    sudo apt-get install python3-venv

    For Fedora:

    sudo dnf install python3-venv

    For macOS with Homebrew: Python 3 typically comes with venv, but if not, you can reinstall it:

    brew install python3

Windows:

  • If Python 3 is installed, venv should be available by default. No additional steps are required.

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:

  • Replace venv_name with the desired name for your virtual environment.
  • After activating the virtual environment, any Python packages you install (e.g., using pip) will be isolated to that environment.
  • To install packages, use:
    pip install package_name