MCPcopy Create free account
hub / github.com/NatronGitHub/Natron / initializePython2

Function initializePython2

Global/PythonUtils.cpp:242–432  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

240PyObject* initializePython3(const std::vector<wchar_t*>& commandLineArgsWide)
241#else
242PyObject* initializePython2(const std::vector<char*>& commandLineArgsUtf8)
243#endif
244{
245 //See https://developer.blender.org/T31507
246 //Python will not load anything in site-packages if this is set
247 //We are sure that nothing in system wide site-packages is loaded, for instance on OS X with Python installed
248 //through macports on the system, the following printf show the following:
249
250 /*Py_GetProgramName is /Applications/Natron.app/Contents/MacOS/Natron
251 Py_GetPrefix is /Applications/Natron.app/Contents/MacOS/../Frameworks/Python.framework/Versions/2.7
252 Py_GetExecPrefix is /Applications/Natron.app/Contents/MacOS/../Frameworks/Python.framework/Versions/2.7
253 Py_GetProgramFullPath is /Applications/Natron.app/Contents/MacOS/Natron
254 Py_GetPath is /Applications/Natron.app/Contents/MacOS/../Frameworks/Python.framework/Versions/2.7/lib/python2.7:/Applications/Natron.app/Contents/MacOS/../Plugins:/Applications/Natron.app/Contents/MacOS/../Frameworks/Python.framework/Versions/2.7/lib/python27.zip:/Applications/Natron.app/Contents/MacOS/../Frameworks/Python.framework/Versions/2.7/lib/python2.7/:/Applications/Natron.app/Contents/MacOS/../Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin:/Applications/Natron.app/Contents/MacOS/../Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac:/Applications/Natron.app/Contents/MacOS/../Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages:/Applications/Natron.app/Contents/MacOS/../Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk:/Applications/Natron.app/Contents/MacOS/../Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old:/Applications/Natron.app/Contents/MacOS/../Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
255 Py_GetPythonHome is ../Frameworks/Python.framework/Versions/2.7/lib
256 Python library is in /Applications/Natron.app/Contents/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages*/
257
258 //Py_NoSiteFlag = 1;
259
260 /////////////////////////////////////////
261 // Py_SetProgramName
262 /////////////////////////////////////////
263 //
264 // Must be done before Py_Initialize (see doc of Py_Initialize)
265 //
266
267#if PY_MAJOR_VERSION >= 3
268 // Python 3
269 Py_SetProgramName(commandLineArgsWide[0]);
270#else
271 // Python 2
272 printf( "Py_SetProgramName(\"%s\")\n", commandLineArgsUtf8[0] );
273 Py_SetProgramName(commandLineArgsUtf8[0]);
274#endif
275
276 /////////////////////////////////////////
277 // Py_Initialize
278 /////////////////////////////////////////
279 //
280 // Initialize the Python interpreter. In an application embedding Python, this should be called before using any other Python/C API functions; with the exception of Py_SetProgramName(), Py_SetPythonHome() and Py_SetPath().
281#if defined(NATRON_CONFIG_SNAPSHOT) || defined(DEBUG)
282 printf("Py_Initialize()\n");
283#endif
284 Py_Initialize();
285 // pythonHome must be const, so that the c_str() pointer is never invalidated
286
287#if PY_MAJOR_VERSION >= 3
288 // Py_SetPath clears sys.prefix and sys.exec_prefix
289 // https://github.com/NatronGitHub/Natron/issues/696
290 PyObject *prefix = PyUnicode_FromWideChar(Py_GetPythonHome(), -1);
291 PySys_SetObject(const_cast<char*>("prefix"), prefix);
292 Py_XDECREF(prefix);
293 PyObject *exec_prefix = PyUnicode_FromWideChar(Py_GetPythonHome(), -1);
294 PySys_SetObject(const_cast<char*>("exec_prefix"), exec_prefix);
295 Py_XDECREF(exec_prefix);
296#endif
297
298 /////////////////////////////////////////
299 // PySys_SetArgv

Callers 1

initPythonMethod · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected