7

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?

jramm
  • 6,415
  • 4
  • 34
  • 73
  • possible duplicate of [python ImportError No module named](http://stackoverflow.com/questions/338768/python-importerror-no-module-named) – Sourav Ghosh Nov 24 '14 at 11:50
  • 1
    No, 1: This is specific to embedding and to the site.py which is the standard library (i.e. very different to not finding some 3rd party module), the question you linked to is not. 2: I specifically stated I did not want to mess with PYTHONHOME. – jramm Nov 24 '14 at 11:53
  • 3
    Seriously, I sometimes wonder if some people don't even read the question and the duplicate they flag... Just like skimming through the heading shortly, "there is one identical word in the heading -> this must be a duplicate". These are not even close to be similar... -.- (and one flag often makes the following people to just agree without having another close look at both the question and the flagged duplicate -> so especially the first flagger should take care of what he is doing...) – mozzbozz Nov 24 '14 at 14:21

1 Answers1

4

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.

aikoven
  • 539
  • 6
  • 8