views:

67

answers:

1

I'm needing 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 msg:

Traceback (most recent call last): File "", line 1, in 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.

Thanks.

+1  A: 

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.

Ignacio Vazquez-Abrams
I'm sorry; I'm new to Python. What do you mean by ''?
Drew
The empty string. Which means the current path in `sys.path`.
Ignacio Vazquez-Abrams
I got it to work... Although I'm unsure how and am trying to replicate the results on another machine. I've tried using sys.path.append as well as manually concatenating strings representing sys.path and my desired path. It seems that I can't have both the system path and my path at the same time.Thanks for the help.
Drew
Got it... Used PYTHONPATH=<working directory> in the ~/.bashrc file.
Drew