get python3 scripts running with venv

This commit is contained in:
Philippe Teuwen 2024-11-09 01:24:34 +01:00
commit 60e932f2f7

View file

@ -469,8 +469,16 @@ static int CmdScriptRun(const char *Cmd) {
// We disallowed in py_conf environment variables interfering with python interpreter's behavior. // We disallowed in py_conf environment variables interfering with python interpreter's behavior.
// Let's manually enable the ones we truly need. // Let's manually enable the ones we truly need.
const char *virtual_env = getenv("VIRTUAL_ENV");
if (virtual_env != NULL) {
size_t length = strlen(virtual_env) + strlen("/bin/python3") + 1;
char python_executable_path[length];
snprintf(python_executable_path, length, "%s/bin/python3", virtual_env);
PyConfig_SetBytesString(&py_conf, &py_conf.executable, python_executable_path);
} else {
// This is required by Proxspace to work with an isolated Python configuration // This is required by Proxspace to work with an isolated Python configuration
PyConfig_SetBytesString(&py_conf, &py_conf.home, getenv("PYTHONHOME")); PyConfig_SetBytesString(&py_conf, &py_conf.home, getenv("PYTHONHOME"));
}
// This is required for allowing `import pm3` in python scripts // This is required for allowing `import pm3` in python scripts
PyConfig_SetBytesString(&py_conf, &py_conf.pythonpath_env, getenv("PYTHONPATH")); PyConfig_SetBytesString(&py_conf, &py_conf.pythonpath_env, getenv("PYTHONPATH"));