79197397

Date: 2024-11-17 14:31:28
Score: 0.5
Natty:
Report link

I decided to try to fill in all the text variables of the configurator and this turned out to be the answer:

wchar_t pythonPath[MAX_PATH * 3];
wchar_t pythonExe[MAX_PATH];
wchar_t pythonHome[] = L"%localappdata%\\Programs\\Python\\Python38"; // L"C:\\Program Files\\Python38";

(void)swprintf_s(pythonPath, L"%s\\Lib;%s\\DLLs;%s\\Lib\\site-packages", pythonHome, pythonHome, pythonHome);
PathCombineW(pythonExe, pythonHome, L"python.exe");

PyConfig config;
PyConfig_InitPythonConfig(&config);
PyConfig_SetString(&config, &config.executable, pythonExe);
PyConfig_SetString(&config, &config.home, pythonHome);
PyConfig_SetString(&config, &config.pythonpath_env, pythonPath);

PyStatus status = Py_InitializeFromConfig(&config);
if (PyStatus_Exception(status) || !Py_IsInitialized()) 
{
    CMyService::LogPythonError(L"Python initialization failed");
    CMyService::LogTextEvent(pythonPath);
    PyConfig_Clear(&config);
    return false;
}

PyConfig_Clear(&config);
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: PorisulkiP