* 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. */
| 279 | * guide Python's default prefix/exec_prefix searching logic. |
| 280 | */ |
| 281 | void 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 |
| 308 | PyObject* DLLDirectoryCookie = nullptr; |
no test coverage detected