set the PYTHONPATH to BLI_gethome_folder("python") if it exists.
authorCampbell Barton <ideasman42@gmail.com>
Fri, 3 Jul 2009 04:38:55 +0000 (04:38 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 3 Jul 2009 04:38:55 +0000 (04:38 +0000)
This lets us distribute blender with our own python module directory (next to ui and io), and avoids the need for a shell script to start blender.

source/blender/python/intern/bpy_interface.c

index 1d18fe36ad95b6680172a9bb67f02d3c35de00da..2b1b72d0307da28404416ec4d59329cb542852dc 100644 (file)
@@ -147,10 +147,43 @@ wchar_t* Py_GetPath(void)
 }
 #endif
 
+
+/* must be called before Py_Initialize */
+void BPY_start_python_path(void)
+{
+       char *py_path_bundle= BLI_gethome_folder("python");
+
+       if(py_path_bundle==NULL)
+               return;
+
+       /* set the environment path */
+       printf("found bundled python: %s\n", py_path_bundle);
+
+#if (defined(WIN32) || defined(WIN64))
+#if defined(FREE_WINDOWS)
+       sprintf(py_path, "PYTHONPATH=%s", py_path_bundle)
+       putenv(py_path);
+#else
+       _putenv_s("PYTHONPATH", py_path_bundle);
+#endif
+#else
+#ifdef __sgi
+       sprintf(py_path, "PYTHONPATH=%s", py_path_bundle)
+       putenv(py_path);
+#else
+       setenv("PYTHONPATH", py_path_bundle, 1); /* initializing the video driver can cause crashes on some systems - Campbell */
+#endif
+#endif
+
+}
+
+
 void BPY_start_python( int argc, char **argv )
 {
        PyThreadState *py_tstate = NULL;
        
+       BPY_start_python_path(); /* allow to use our own included python */
+
        Py_Initialize(  );
        
        //PySys_SetArgv( argc_copy, argv_copy );