467,222 Members | 1,488 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,222 developers. It's quick & easy.

having trouble importing a module from local directory

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.

May 12 '06 #1
  • viewed: 1347
Share:
2 Replies
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.

--
Marcelo Ramos
Fedora Core 5 | 2.6.16
Socio UYLUG Nro 125

May 12 '06 #2
newbie reply, but how do i go about doing that? thanks!

May 14 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Penn Markham | last post: by
5 posts views Thread by Boomer | last post: by
1 post views Thread by Frans Englich | last post: by
reply views Thread by Mark English | last post: by
3 posts views Thread by Charles Krug | last post: by
3 posts views Thread by Chanman | last post: by
reply views Thread by norseman | last post: by
reply views Thread by Adict | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.