void PythonModule::initialize() throw (VoreenException) { VoreenModule::initialize(); // // Initialize Python interpreter // LINFO("Python version: " << Py_GetVersion()); // Pass program name to the Python interpreter char str_pyvoreen[] = "PyVoreen"; Py_SetProgramName(str_pyvoreen); // Initialize the Python interpreter. Required. Py_InitializeEx(false); if (!Py_IsInitialized()) throw VoreenException("Failed to initialize Python interpreter"); // required in order to use threads. PyEval_InitThreads(); // init ResourceManager search path addPath(""); addPath(VoreenApplication::app()->getScriptPath()); addPath(VoreenApplication::app()->getModulePath("python/scripts")); // init Python's internal module search path addModulePath(VoreenApplication::app()->getScriptPath()); addModulePath(VoreenApplication::app()->getModulePath("python/scripts")); // // Redirect script output from std::cout to voreen_print function (see above) // // import helper module if (!Py_InitModule("voreen_internal", internal_methods)) { LWARNING("Failed to init helper module 'voreen_internal'"); } // load output redirector script and run it once std::string filename = "outputcatcher.py"; LDEBUG("Loading Python init script '" << filename << "'"); PythonScript* initScript = load(filename); if (initScript) { if (!initScript->run()) LWARNING("Failed to run init script '" << filename << "': " << initScript->getLog()); dispose(initScript); } else { LWARNING("Failed to load init script '" << filename << "'"); } // // Create actual Voreen Python bindings // pyVoreen_ = new PyVoreen(); }
void PyInviwo::initPythonCInterface() { if (isInit_) return; isInit_ = true; LogInfo("Python version: " + toString(Py_GetVersion())); wchar_t programName[] = L"PyInviwo"; Py_SetProgramName(programName); #ifdef WIN32 Py_NoSiteFlag = 1; #endif Py_InitializeEx(false); if (!Py_IsInitialized()) { LogError("Python is not Initialized"); return; } PyEval_InitThreads(); mainDict_ = PyDict_New(); modulesDict_ = PyImport_GetModuleDict(); importModule("builtins"); importModule("sys"); importModule("os"); importModule("glob"); importModule("random"); addModulePath(InviwoApplication::getPtr()->getBasePath() + "/modules/python3/scripts"); initDefaultInterfaces(); initOutputRedirector(); }
void PyInviwo::initPythonCInterface(Python3Module* module) { if (isInit_) return; isInit_ = true; LogInfo("Python version: " + toString(Py_GetVersion())); wchar_t programName[] = L"PyInviwo"; Py_SetProgramName(programName); Py_InitializeEx(false); if (!Py_IsInitialized()) { LogError("Python is not Initialized"); return; } PyEval_InitThreads(); importModule("builtins"); importModule("sys"); dict_ = PyImport_GetModuleDict(); registerPyModule(&Inviwo_Internals_Module_Def, "inviwo_internal"); registerPyModule(&Inviwo_Module_Def, "inviwo"); addModulePath(module->getPath() + "/scripts"); initOutputRedirector(module); }