473,508 Members | 2,195 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
2 1515
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
4935
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
5
1512
by: Boomer | last post by:
Hi all, I'm new to python which explains my problems with this. I'm trying to import a .csv file(from excel) into some fields on my company's software system(which interfaces to an sql database....
1
1613
by: Frans Englich | last post by:
Hello all, I have a couple of questions related to module importing. 1) When I start my Python program with `python foo.py` instead of simply adding a interpreter comment on the first line and...
0
1360
by: Mark English | last post by:
Basic problem: If there is a C-extension module in a package and it tries to import another python module in the same package without using the fully qualified path, the import fails. Config:...
3
1831
by: Charles Krug | last post by:
List: I'm trying to use the example files from Programming Python, 2nd Ed. I've copied them into c:\Python24\Examples\PP2E. Launching any of the examples programs by themselves seems to work...
0
2212
by: UncleRic | last post by:
Environment: Mac OS X (10.4.10) on MacBook Pro I'm a Perl Neophyte. I've downloaded the XML::Parser module and am attempting to install it in my working directory (referenced via PERL5LIB env): ...
3
19304
by: Chanman | last post by:
This is probably a simple question to most of you, but here goes. I've downloaded the xlrd (version 0.6.1) module and placed in in the site-packages folder. Now, when I write a script, I type: ...
0
1644
by: norseman | last post by:
mercado mercado wrote: ========================================================== Yes, but you may not like it. I do what you do. Prod and devel subdirs. I store the paths in a var at the top...
2
2199
by: Robert Dailey | last post by:
Hi, I'm currently using boost::python::import() to import Python modules, so I'm not sure exactly which Python API function it is calling to import these files. I posted to the Boost.Python...
0
7127
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7054
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7501
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5633
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5056
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4713
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1564
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
768
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.