Skip to content Skip to sidebar Skip to footer

Embedding Python Into C - Importing Modules

I am having problems using the Embedded Python for C as per the Documentation - Whenever I try using imported modules I get an : Unhandled exception at 0x1e089e85 in PythonIncl.ex

Solution 1:

Check the result of the PyImport_ImportModule call: It fails and returns NULL. That is because by default, the current directory is not in the search path. Add

PySys_SetPath("."); // before ..
mymod = PyImport_ImportModule("reverse");

to add the current directory to the module search path and make your example work.

Solution 2:

You're proceeding without checking for errors, so it's no shock your code fails this way. From your description, it sounds like mymod is NULL, which would be consistent with a failed import. One possible cause of the failed import is that the reverse.py you posted has a syntax error.

Post a Comment for "Embedding Python Into C - Importing Modules"