Embedding Python into C - importing modules

后端 未结 2 1528
-上瘾入骨i
-上瘾入骨i 2021-02-09 12:38

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 0x

2条回答
  •  北荒
    北荒 (楼主)
    2021-02-09 13:13

    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.

提交回复
热议问题