Skip to content
Permalink
Browse files

Add support for PYTHONSTARTUP-like environment variable, PYQGIS_STARTUP

- Different than user's 'startup.py,' since it is loaded just after Py_Initialize, specifically from env variable
- Useful for cleaning sys.path, e.g. isolating/loading the initial environ without requiring a virt env, like homebrew or MacPorts installs on Mac
  • Loading branch information
dakcarto committed Sep 24, 2013
1 parent 3fce4a5 commit 4c1b95ba9ee0d5f0e4c9664bd293003ef280ba31
Showing with 8 additions and 0 deletions.
  1. +8 −0 src/python/qgspythonutilsimpl.cpp
@@ -61,6 +61,14 @@ void QgsPythonUtilsImpl::initPython( QgisInterface* interface )
runString( "import sys" ); // import sys module (for display / exception hooks)
runString( "import os" ); // import os module (for user paths)

// support for PYTHONSTARTUP-like environment variable: PYQGIS_STARTUP
// (unlike PYTHONHOME and PYTHONPATH, PYTHONSTARTUP is not supported for embedded interpreter by default)
// this is different than user's 'startup.py' (below), since it is loaded just after Py_Initialize
// it is very useful for cleaning sys.path, which may have undesireable paths, or for
// isolating/loading the initial environ without requiring a virt env, e.g. homebrew or MacPorts installs on Mac
runString( "pyqgstart = os.getenv('PYQGIS_STARTUP')\n" );
runString( "if pyqgstart is not None and os.path.exists(pyqgstart): execfile(pyqgstart)\n" );

#ifdef Q_OS_WIN
runString( "oldhome=None" );
runString( "if os.environ.has_key('HOME'): oldhome=os.environ['HOME']\n" );

0 comments on commit 4c1b95b

Please sign in to comment.
You can’t perform that action at this time.