Python: disable environment variables by default

This avoids the problem where Blender doesn't start because
the PYTHONPATH points to an incompatible Python version,
see T72807.

Previously we chose to assume people who set the PYTHONPATH know what
they're doing, however users may have set this for non Blender projects.
So it's not obvious that this is the cause of Blender not to launch
on their system.

To use Python's environment vars, pass the argument:
--python-use-system-env

Note that this only impacts Python run-time environment variables
documented in `python --help`, Access from `os.environ` remains.
This commit is contained in:
2020-01-16 21:11:05 +11:00
parent abdaf2a4f5
commit 7c2f0074f3
3 changed files with 29 additions and 0 deletions

View File

@@ -84,6 +84,9 @@ CLG_LOGREF_DECLARE_GLOBAL(BPY_LOG_RNA, "bpy.rna");
* stop bpy_context_clear from invalidating. */
static int py_call_level = 0;
/* Set by command line arguments before Python starts. */
static bool py_use_system_env = false;
// #define TIME_PY_RUN // simple python tests. prints on exit.
#ifdef TIME_PY_RUN
@@ -276,6 +279,10 @@ void BPY_python_start(int argc, const char **argv)
* While harmless, it's noisy. */
Py_FrozenFlag = 1;
/* Only use the systems environment variables when explicitly requested.
* Since an incorrect 'PYTHONPATH' causes difficult to debug errors, see: T72807. */
Py_IgnoreEnvironmentFlag = !py_use_system_env;
Py_Initialize();
// PySys_SetArgv(argc, argv); /* broken in py3, not a huge deal */
@@ -408,6 +415,12 @@ void BPY_python_reset(bContext *C)
BPY_modules_load_user(C);
}
void BPY_python_use_system_env(void)
{
BLI_assert(!Py_IsInitialized());
py_use_system_env = true;
}
static void python_script_error_jump_text(struct Text *text)
{
int lineno;