How to set apache2 environment variables in wsgi file (Flask)
Question: Currently I work with Flask micro framework. How to set Environment variables
in wsgi file? I have done this in apache2 envvars file like this:

    
    
    export PRODROOT=${PRODROOT:-/home/peter/Lv-164.UI/ecomap}
    export PYSRCROOT=${PYSRCROOT:-${PRODROOT}/src/python}
    export CONFROOT=${CONFROOT:-${PRODROOT}/etc}
    export PYTHONPATH=${PRODROOT}/src/python
    

How I can do that in wsgi file? Thanks for your attention.


Answer: The wsgi file is just a Python file, so you can use `os.environ` to set
environment variables for your code. E.g. in your wsgi file:

    
    
    import os
    os.environ['PRODROOT'] = '/home/peter/Lv-164.UI/ecomap'
    os.environ['PYSRCROOT'] = os.environ['PRODROOT'] + '/src/python'
    os.environ['CONFROOT'] = os.environ['PRODROOT'] + '/etc'
    os.environ['PYTHONPATH'] = os.environ['PRODROOT'] + '/src/python'
    
    from yourpackage.yourapp import app as application
    

I'm not sure that setting `PYTHONPATH` will work in this scenario (though it's
worth a try). If you're using `mod_wsgi` then you can set it with the
`WSGIPythonPath` directive.

<https://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIPythonPath>

