Untitled
unknown
plain_text
5 months ago
1.1 kB
2
Indexable
void InitializePython() { PyConfig config; PyConfig_InitPythonConfig(&config); // Initialize the config structure // Set the Python Home const wchar_t* pythonHome = L"D:/ProgrammingLanguage/Python311"; // Update this path config.home = pythonHome; // Add the Python Home to the module search paths PyStatus status = PyWideStringList_Append(&config.module_search_paths, pythonHome); if (PyStatus_Exception(status)) { std::cerr << "Failed to append to module search paths!" << std::endl; PyConfig_Clear(&config); return; } // Set the program name config.program_name = L"NiCatsStudentClient"; // Optionally, set other fields in `config` config.isolated = 0; // Initialize the Python runtime from the config PyStatus init_status = Py_InitializeFromConfig(&config); if (PyStatus_Exception(init_status)) { std::cerr << "Python initialization failed!" << std::endl; PyConfig_Clear(&config); return; } std::cout << "Python Initialized!" << std::endl; // Free resources after initialization PyConfig_Clear(&config); }
Editor is loading...
Leave a Comment