Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedding Python: No module named site

I'm embedding python in a C application. I have downloaded the standard python dist and placed it relative to program and used this to link & build the C application.

This works fine on my devel machine and the application runs against this version of python.

When I bundle up the application and the python distro and deploy it, Im getting the following error:

ImportError: No module named site

This can be fixed by setting PYTHONHOME to the path to this 'local' python distribution, but I don't want to mess around with any python installation the user may already have, so would rather not set this variable.

Any ideas how to correctly bundle the python interpreter & lib without interfering with any possible versions of python that may already be on a target machine?

like image 437
jramm Avatar asked Nov 24 '14 11:11

jramm


1 Answers

Just add

Py_SetPythonHome(pathToPython);

before Py_Initialize call. pathToPython should be the path to python distribution, for Windows it is the folder that contains Lib and DLLs folders.

like image 126
aikoven Avatar answered Sep 28 '22 17:09

aikoven