Embedding Python and program path

arve.knudsen at gmail.com arve.knudsen at gmail.com
Thu Jan 15 17:02:03 CET 2009


In my application embedding Python I want to have the standard Python
module path, so I try to achieve this by setting the program path to
that of the the interpreter. Even though I call Py_SetProgramName
before Py_InitializeEx, however, Python thinks the program path (as
returned by Py_GetProgramFullPath) is that of my embedding executable.

I would love if someone could explain what is going wrong here, and
eventually provide a better solution for inheriting the Python
interpreter's standard module path.

Test application demonstrating the problem.

#include <Python.h>

int main() {
    // Hardcoded for simplicity
    Py_SetProgramName("C:\\Python26\\python.exe");
    Py_InitializeEx(0);
    printf("Program path: %s\n", Py_GetProgramFullPath());
    Py_Finalize();

    return 0;
}


Thanks,
Arve Knudsen



More information about the Python-list mailing list