Skip to content

Instantly share code, notes, and snippets.

@dakcarto
Created January 27, 2014 01:53
Show Gist options
  • Select an option

  • Save dakcarto/8642149 to your computer and use it in GitHub Desktop.

Select an option

Save dakcarto/8642149 to your computer and use it in GitHub Desktop.
qgis-20_pyqgis-startup
diff --git a/src/python/qgspythonutilsimpl.cpp b/src/python/qgspythonutilsimpl.cpp
index 393471c..bdc2665 100644
--- a/src/python/qgspythonutilsimpl.cpp
+++ b/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" );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment