diff --git a/source/blender/python/generic/py_capi_utils.c b/source/blender/python/generic/py_capi_utils.c index 6c02e293789..d944cb435d0 100644 --- a/source/blender/python/generic/py_capi_utils.c +++ b/source/blender/python/generic/py_capi_utils.c @@ -893,18 +893,6 @@ void PyC_MainModule_Restore(PyObject *main_mod) */ 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 */ @@ -915,19 +903,14 @@ void PyC_SetHomePath(const char *py_path_bundle) } # endif - { - wchar_t py_path_bundle_wchar[1024]; + /* Set the environment path. */ + wchar_t py_path_bundle_wchar[1024]; - /* Can't use this, on linux gives bug: T23018, - * TODO: try LANG="en_US.UTF-8" /usr/bin/blender, suggested 2008 */ - /* mbstowcs(py_path_bundle_wchar, py_path_bundle, FILE_MAXDIR); */ + /* Can't use `mbstowcs` on linux gives bug: T23018. */ + BLI_strncpy_wchar_from_utf8( + py_path_bundle_wchar, py_path_bundle, ARRAY_SIZE(py_path_bundle_wchar)); - BLI_strncpy_wchar_from_utf8( - py_path_bundle_wchar, py_path_bundle, ARRAY_SIZE(py_path_bundle_wchar)); - - Py_SetPythonHome(py_path_bundle_wchar); - // printf("found python (wchar_t) '%ls'\n", py_path_bundle_wchar); - } + Py_SetPythonHome(py_path_bundle_wchar); } bool PyC_IsInterpreterActive(void) diff --git a/source/blender/python/intern/bpy.h b/source/blender/python/intern/bpy.h index e2fe84f71c7..25a047edfb5 100644 --- a/source/blender/python/intern/bpy.h +++ b/source/blender/python/intern/bpy.h @@ -35,6 +35,7 @@ void BPY_atexit_unregister(void); extern struct CLG_LogRef *BPY_LOG_CONTEXT; extern struct CLG_LogRef *BPY_LOG_RNA; +extern struct CLG_LogRef *BPY_LOG_INTERFACE; #ifdef __cplusplus } diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index d343b4fff10..0b11ac639c7 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -80,6 +80,7 @@ /* Logging types to use anywhere in the Python modules. */ CLG_LOGREF_DECLARE_GLOBAL(BPY_LOG_CONTEXT, "bpy.context"); +CLG_LOGREF_DECLARE_GLOBAL(BPY_LOG_INTERFACE, "bpy.interface"); CLG_LOGREF_DECLARE_GLOBAL(BPY_LOG_RNA, "bpy.rna"); /* for internal use, when starting and ending python scripts */ @@ -304,7 +305,6 @@ void BPY_python_start(bContext *C, int argc, const char **argv) { #ifndef WITH_PYTHON_MODULE PyThreadState *py_tstate = NULL; - const char *py_path_bundle = BKE_appdir_folder_id(BLENDER_SYSTEM_PYTHON, NULL); /* Needed for Python's initialization for portable Python installations. * We could use #Py_SetPath, but this overrides Python's internal logic @@ -321,8 +321,21 @@ void BPY_python_start(bContext *C, int argc, const char **argv) /* must run before python initializes */ PyImport_ExtendInittab(bpy_internal_modules); - /* allow to use our own included python */ - PyC_SetHomePath(py_path_bundle); + /* Allow to use our own included Python. `py_path_bundle` may be NULL. */ + { + const char *py_path_bundle = BKE_appdir_folder_id(BLENDER_SYSTEM_PYTHON, NULL); + if (py_path_bundle != NULL) { + PyC_SetHomePath(py_path_bundle); + } + else { + /* Common enough to use the system Python on Linux/Unix, warn on other systems. */ +# if defined(__APPLE__) || defined(_WIN32) + fprintf(stderr, + "Bundled Python not found and is expected on this platform " + "(the 'install' target may have not been built)\n"); +# endif + } + } /* Without this the `sys.stdout` may be set to 'ascii' * (it is on my system at least), where printing unicode values will raise