MCPcopy Create free account
hub / github.com/Kitware/VTK / SetupPythonPrefix

Function SetupPythonPrefix

Utilities/PythonInterpreter/vtkPythonInterpreter.cxx:281–305  ·  view source on GitHub ↗

* Since vtkPythonInterpreter is often used outside CPython executable, e.g. * vtkpython, the default logic to locate Python standard libraries used by * Python (which depends on the executable path) may fail or pickup incorrect * Python libs. This methods address the issue by setting program name to help * guide Python's default prefix/exec_prefix searching logic. */

Source from the content-addressed store, hash-verified

279 * guide Python's default prefix/exec_prefix searching logic.
280 */
281void SetupPythonPrefix(bool isolated)
282{
283 using systools = vtksys::SystemTools;
284
285 // Check if we're using an isolated Python.
286 if (isolated)
287 {
288 VTKPY_DEBUG_MESSAGE("Isolated Python detected; skipping setting up of program path.");
289 return;
290 }
291
292 std::string pythonlib = vtkGetLibraryPathForSymbol(Py_InitializeEx);
293 if (pythonlib.empty())
294 {
295 VTKPY_DEBUG_MESSAGE("static Python build or `Py_InitializeEx` library couldn't be found. "
296 "Set `PYTHONHOME` if Python standard library fails to load.");
297 return;
298 }
299
300 const std::string newprogramname =
301 systools::GetFilenamePath(pythonlib) + VTK_PATH_SEPARATOR "vtkpython";
302 VTKPY_DEBUG_MESSAGE("calling vtkPythonInterpreter::SetProgramName("
303 << newprogramname << ") to aid in setup of Python prefix.");
304 vtkPythonInterpreter::SetProgramName(newprogramname.c_str());
305}
306
307#ifdef vtkPythonInterpreter_USE_DIRECTORY_COOKIE
308PyObject* DLLDirectoryCookie = nullptr;

Callers 1

InitializeWithArgsMethod · 0.85

Calls 2

emptyMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected