在C中嵌入Python:导入本地模块时出现问题

Dre*_*rew 5 c python import module embedding

我需要在基于C的应用程序中运行Python脚本.我能够从Python库导入标准模块,即:

PyRun_SimpleString("import sys")
Run Code Online (Sandbox Code Playgroud)

但是当我尝试导入本地模块时 can

PyRun_SimpleString("import can")
Run Code Online (Sandbox Code Playgroud)

返回错误消息:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named can
Run Code Online (Sandbox Code Playgroud)

当我import can在IPython中键入命令时,系统能够找到它.

如何将我的应用程序与can链接?我已经尝试设置PYTHONPATH到我的工作目录.

Ign*_*ams 9

嵌入Python库不添加''sys.path喜欢交互式解释呢.使用PySys_SetPath()添加相应的目录.

哦,嘿,看看我发现了什么.