Skip to content

Commit

Permalink
Eliminate use of deprecated Py_SetProgramName function
Browse files Browse the repository at this point in the history
  • Loading branch information
speth authored and ischoegl committed Nov 21, 2022
1 parent d5068c7 commit f04d482
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/extensions/PythonExtensionManager.cpp
Expand Up @@ -88,6 +88,9 @@ PythonExtensionManager::PythonExtensionManager()
// Update the path to include the virtual environment, if one is active
const char* venv_path = getenv("VIRTUAL_ENV");
if (venv_path != nullptr) {
PyConfig pyconf;
PyConfig_InitPythonConfig(&pyconf);

#ifdef _WIN32
string suffix = "\\Scripts\\python.exe";
#else
Expand All @@ -96,7 +99,10 @@ PythonExtensionManager::PythonExtensionManager()
string path(venv_path);
path += suffix;
wstring wpath = wstring_convert<codecvt_utf8<wchar_t>>().from_bytes(path);
Py_SetProgramName(wpath.c_str());
PyStatus status = PyConfig_SetString(&pyconf, &pyconf.program_name,
wpath.c_str());
checkPythonError(PyStatus_Exception(status), "PyConfig_SetString failed");
Py_InitializeFromConfig(&pyconf);
} else {
#if defined(CT_PYTHONHOME) && defined(_WIN32)
const char* old_pythonhome = getenv("PYTHONHOME");
Expand All @@ -106,8 +112,8 @@ PythonExtensionManager::PythonExtensionManager()
_putenv(pythonhome.c_str());
}
#endif
Py_Initialize();
}
Py_Initialize();
}

if (s_imported) {
Expand Down

0 comments on commit f04d482

Please sign in to comment.