having trouble importing a module from local directory

V

vduber6er

First off this is in unix.

I have a C file that has python embedded in it. In the script I have
the following

PyRun_SimpleString(code);

where
code = "import mymodule"

however I get this error

Traceback (most recent call last):
File "<string>", line 1, in ?
ImportError: No module named mymodule
Object not found
Segmentation fault

If i just run python from my local path then type "import mymodule" in
the python prompt this is fine. I'm guessing when I am embedding my
python script in the C code the local directory is no longer the
directory where my C code resides. How can i tell python to load the
module from my current local directory?

Thanks.
 
M

Marcelo Ramos

vduber6er escribió:
First off this is in unix.

I have a C file that has python embedded in it. In the script I have
the following

PyRun_SimpleString(code);

where
code = "import mymodule"

however I get this error

Traceback (most recent call last):
File "<string>", line 1, in ?
ImportError: No module named mymodule
Object not found
Segmentation fault

If i just run python from my local path then type "import mymodule" in
the python prompt this is fine. I'm guessing when I am embedding my
python script in the C code the local directory is no longer the
directory where my C code resides. How can i tell python to load the
module from my current local directory?

Try adding the directory where your mymodule module lives to the
PYTHONPATH environment variable before running your c program.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top