Skip to main content

Working with virtual environments

How to create a python virtual environment​

  1. Create the virtual environment​

    python -m venv env
  2. Activate the virtual environment​

    • for windows
    env\Scripts\activate
    • for Linux / macOS
    source env/bin/activate
  3. Deactivate the virtual environment​

    deactivate

How to set environment variables​

  • for CMD SET VARIABLE_NAME=VALUE​

    SET FLASK_APP=app.py
    SET FLASK_ENV=development
    SET FLASK_DEBUG=true
    SET SQLALCHEMY_DATABASE_URI=postgresql://user:password@host:port/dbname
  • for BASH export VARIABLE_NAME=VALUE​

    export FLASK_APP=app.py
    export FLASK_ENV=development
    export FLASK_DEBUG=true
    export SQLALCHEMY_DATABASE_URI=postgresql://user:password@host:port/dbname
  • for POWERSHELL $env:VARIABLE_NAME=VALUE​

    $env:FLASK_APP=app.py
    $env:FLASK_ENV=development
    $env:FLASK_DEBUG=true
    $env:SQLALCHEMY_DATABASE_URI=postgresql://user:password@host:port/dbname
  • Configuring pyenv on Mac​

    Create a file called .zshrc in your home directory and add the following scripts to it to enable discovery of active python version.

    export PYENV_ROOT="$HOME/.pyenv"
    export PATH="$PYENV_ROOT/bin:$PATH"
    eval "$(pyenv init -)"