Python attachment: no module named site

I am embedding python in a C application. I downloaded the standard python python and placed it relative to the program and used it to link and build the C application.

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

When I build the application and python distribution and deploy it, Im gets the following error:

ImportError: No module named site 

This can be fixed by installing PYTHONHOME in the path to this "local" python distribution, but I don’t want to interfere with any python installation that the user may already have, so you should not set this variable.

Any ideas on properly binding the python interpreter and lib without interfering with any possible versions of python that might already be on the target machine?

+5
source share
1 answer

Just add

 Py_SetPythonHome(pathToPython); 

before calling Py_Initialize . pathToPython must be a python distribution path, for Windows it is a folder containing Lib and DLLs folders.

+3
source

Source: https://habr.com/ru/post/1207581/


All Articles