[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [36208] trunk/blender/source: fix [#26951] blenderplayer and runtimes will not load

Campbell Barton ideasman42 at gmail.com
Mon Apr 18 10:27:51 CEST 2011


Revision: 36208
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36208
Author:   campbellbarton
Date:     2011-04-18 08:27:50 +0000 (Mon, 18 Apr 2011)
Log Message:
-----------
fix [#26951] blenderplayer and runtimes will not load
blenderplayer wasn't finding bundled python, eg: ./2.57/python/lib

Modified Paths:
--------------
    trunk/blender/source/blender/python/generic/py_capi_utils.c
    trunk/blender/source/blender/python/generic/py_capi_utils.h
    trunk/blender/source/blender/python/intern/bpy_interface.c
    trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp

Modified: trunk/blender/source/blender/python/generic/py_capi_utils.c
===================================================================
--- trunk/blender/source/blender/python/generic/py_capi_utils.c	2011-04-18 07:11:40 UTC (rev 36207)
+++ trunk/blender/source/blender/python/generic/py_capi_utils.c	2011-04-18 08:27:50 UTC (rev 36208)
@@ -30,6 +30,8 @@
 
 #include "py_capi_utils.h"
 
+#include "BKE_font.h" /* only for utf8towchar, should replace with py funcs but too late in release now */
+
 #define PYC_INTERPRETER_ACTIVE (((PyThreadState*)_Py_atomic_load_relaxed(&_PyThreadState_Current)) != NULL)
 
 /* for debugging */
@@ -284,6 +286,48 @@
 	Py_XDECREF(main_mod);
 }
 
+/* must be called before Py_Initialize, expects output of BLI_get_folder(BLENDER_PYTHON, NULL) */
+void PyC_SetHomePath(const char *py_path_bundle)
+{
+	if(py_path_bundle==NULL) {
+		/* Common enough to have bundled *nix python but complain on OSX/Win */
+#if defined(__APPLE__) || defined(_WIN32)
+		fprintf(stderr, "Warning! bundled python not found and is expected on this platform. (if you built with CMake: 'install' target may have not been built)\n");
+#endif
+		return;
+	}
+	/* set the environment path */
+	printf("found bundled python: %s\n", py_path_bundle);
+
+#ifdef __APPLE__
+	/* OSX allow file/directory names to contain : character (represented as / in the Finder)
+	 but current Python lib (release 3.1.1) doesn't handle these correctly */
+	if(strchr(py_path_bundle, ':'))
+		printf("Warning : Blender application is located in a path containing : or / chars\
+			   \nThis may make python import function fail\n");
+#endif
+
+#ifdef _WIN32
+	/* cmake/MSVC debug build crashes without this, why only
+	   in this case is unknown.. */
+	{
+		BLI_setenv("PYTHONPATH", py_path_bundle);
+	}
+#endif
+
+	{
+		static wchar_t py_path_bundle_wchar[1024];
+
+		/* cant use this, on linux gives bug: #23018, TODO: try LANG="en_US.UTF-8" /usr/bin/blender, suggested 22008 */
+		/* mbstowcs(py_path_bundle_wchar, py_path_bundle, FILE_MAXDIR); */
+
+		utf8towchar(py_path_bundle_wchar, py_path_bundle);
+
+		Py_SetPythonHome(py_path_bundle_wchar);
+		// printf("found python (wchar_t) '%ls'\n", py_path_bundle_wchar);
+	}
+}
+
 /* Would be nice if python had this built in */
 void PyC_RunQuicky(const char *filepath, int n, ...)
 {

Modified: trunk/blender/source/blender/python/generic/py_capi_utils.h
===================================================================
--- trunk/blender/source/blender/python/generic/py_capi_utils.h	2011-04-18 07:11:40 UTC (rev 36207)
+++ trunk/blender/source/blender/python/generic/py_capi_utils.h	2011-04-18 08:27:50 UTC (rev 36208)
@@ -48,4 +48,6 @@
 void PyC_MainModule_Backup(PyObject **main_mod);
 void PyC_MainModule_Restore(PyObject *main_mod);
 
+void PyC_SetHomePath(const char *py_path_bundle);
+
 #endif // PY_CAPI_UTILS_H

Modified: trunk/blender/source/blender/python/intern/bpy_interface.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_interface.c	2011-04-18 07:11:40 UTC (rev 36207)
+++ trunk/blender/source/blender/python/intern/bpy_interface.c	2011-04-18 08:27:50 UTC (rev 36208)
@@ -164,52 +164,6 @@
 	bpy_context_module->ptr.data= (void *)C;
 }
 
-/* must be called before Py_Initialize */
-#ifndef WITH_PYTHON_MODULE
-static void bpy_python_start_path(void)
-{
-	char *py_path_bundle= BLI_get_folder(BLENDER_PYTHON, NULL);
-
-	if(py_path_bundle==NULL) {
-		/* Common enough to have bundled *nix python but complain on OSX/Win */
-#if defined(__APPLE__) || defined(_WIN32)
-		fprintf(stderr, "Warning! bundled python not found and is expected on this platform. (if you built with CMake: 'install' target may have not been built)\n");
-#endif
-		return;
-	}
-	/* set the environment path */
-	printf("found bundled python: %s\n", py_path_bundle);
-
-#ifdef __APPLE__
-	/* OSX allow file/directory names to contain : character (represented as / in the Finder)
-	 but current Python lib (release 3.1.1) doesn't handle these correctly */
-	if(strchr(py_path_bundle, ':'))
-		printf("Warning : Blender application is located in a path containing : or / chars\
-			   \nThis may make python import function fail\n");
-#endif
-	
-#ifdef _WIN32
-	/* cmake/MSVC debug build crashes without this, why only
-	   in this case is unknown.. */
-	{
-		BLI_setenv("PYTHONPATH", py_path_bundle);	
-	}
-#endif
-
-	{
-		static wchar_t py_path_bundle_wchar[FILE_MAX];
-
-		/* cant use this, on linux gives bug: #23018, TODO: try LANG="en_US.UTF-8" /usr/bin/blender, suggested 22008 */
-		/* mbstowcs(py_path_bundle_wchar, py_path_bundle, FILE_MAXDIR); */
-
-		utf8towchar(py_path_bundle_wchar, py_path_bundle);
-
-		Py_SetPythonHome(py_path_bundle_wchar);
-		// printf("found python (wchar_t) '%ls'\n", py_path_bundle_wchar);
-	}
-}
-#endif
-
 void BPY_context_set(bContext *C)
 {
 	BPy_SetContext(C);
@@ -242,7 +196,8 @@
 	/* must run before python initializes */
 	PyImport_ExtendInittab(bpy_internal_modules);
 
-	bpy_python_start_path(); /* allow to use our own included python */
+	/* allow to use our own included python */
+	PyC_SetHomePath(BLI_get_folder(BLENDER_PYTHON, NULL));
 
 	/* Python 3.2 now looks for '2.57/python/include/python3.2d/pyconfig.h' to parse
 	 * from the 'sysconfig' module which is used by 'site', so for now disable site.

Modified: trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp	2011-04-18 07:11:40 UTC (rev 36207)
+++ trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp	2011-04-18 08:27:50 UTC (rev 36208)
@@ -1758,6 +1758,7 @@
 
 /**
  * Python is not initialised.
+ * see bpy_interface.c's BPY_python_start() which shares the same functionality in blender.
  */
 PyObject* initGamePlayerPythonScripting(const STR_String& progname, TPythonSecurityLevel level, Main *maggie, int argc, char** argv)
 {
@@ -1779,6 +1780,9 @@
 	/* must run before python initializes */
 	PyImport_ExtendInittab(bge_internal_modules);
 
+	/* find local python installation */
+	PyC_SetHomePath(BLI_get_folder(BLENDER_PYTHON, NULL));
+
 	Py_Initialize();
 	
 	if(argv && first_time) { /* browser plugins dont currently set this */




More information about the Bf-blender-cvs mailing list