Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedding Python in C: Having problems importing local modules

I need to run Python scripts within a C-based app. I am able to import standard modules from the Python libraries i.e.:

PyRun_SimpleString("import sys")

But when I try to import a local module can

PyRun_SimpleString("import can")

returns the error message:

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

When I type the command import can in IPython, the system is able to find it.

How can I link my app with can? I've tried setting PYTHONPATH to my working directory.

like image 276
Drew Avatar asked May 26 '10 23:05

Drew


1 Answers

Embedding the Python library does not add '' to sys.path like the interactive interpreter does. Use PySys_SetPath() to add the appropriate directory.

Oh hey, look what I found.

like image 197
Ignacio Vazquez-Abrams Avatar answered Sep 26 '22 01:09

Ignacio Vazquez-Abrams