#include #include void pythonCpp::activateVirtualEnv(const std::string& pyPath, const std::string& venvName) { std::string venvPath = pyPath + "/" + venvName; SetEnvironmentVariable("PYTHONHOME", pyPath.c_str()); SetEnvironmentVariable("PYTHONPATH", (venvPath + "/Lib;" + venvPath + "/Lib/site-packages").c_str()); } bool pythonCpp::runPythonScript_R(const std::string& scriptPath) { FILE* file = fopen(scriptPath.c_str(), "r"); if (file == nullptr) { std::cerr << "Failed to open Python script: " << scriptPath << std::endl; return false; } PyRun_SimpleFile(file, scriptPath.c_str()); fclose(file); return true; } bool pythonCpp::runPythonScript(const std::string& scriptPath) { PyObject* obj = Py_BuildValue("s", scriptPath.c_str()); FILE* file = _Py_fopen_obj(obj, "r+"); if (file == NULL) { return false; } PyRun_SimpleFile(file, scriptPath.c_str()); Py_DECREF(obj); return true; }