Embedding Python: No module named site

2.6k views Asked by At

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?

1

There are 1 answers

0
aikoven On

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.