472,954 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,954 software developers and data experts.

Num Array problem with Embedding python in C

I'm having a problem ........

I've stripped all my code to help isolate the problem.

Its seems to be with importing numarray when python is embedded in C.

I have a simple C program it Opens Python imports a script and
then Closes Python

like so .......

int main(int argc,char *argv[])
{

int count = 0;
PyObject *pmod;

while ( count < 10)
{

/*
** Initialize Python
*/

Py_Initialize();
printf("\nOpen Python ---- >");

pmod = PyImport_ImportModule("test");

Py_DECREF(pmod);

/*
** Close Python
*/

Py_Finalize();
printf("\n<---- Closed Python");
/*
** Do this 10 times !
*/
count++;

}
getchar();
return(0);

}

and thats it !

The script it calls is test.py its very simple , it imports numarray
and then returns. like so .......

-----------------------
test.py
-----------------------
#Imports
from numarray import *

def test_func():
return (99)
-----------------------
end of file
-----------------------
The first time it is called from my C code
it all works fine ! ( but only the first time ! )

In the second iteration above test .c crashes

It has something to do with importing numarray.
Beacase if you comment out the import line i.e

-----------------------
test.py
-----------------------
#Imports
# Commented out !
#from numarray import *

def test_func():
return (99)
-----------------------
end of file
-----------------------

its scrolls through the while loop and works fine.

Its all very odd . any ideas ?
I'm using Python 2.3.3 and Python 2.3 numarray - 0.8

Thanks in advance

Keith.
Jul 18 '05 #1
1 1932
yo***********@hotmail.com wrote:
I'm having a problem ........

I've stripped all my code to help isolate the problem.

Its seems to be with importing numarray when python is embedded in C.

I have a simple C program it Opens Python imports a script and
then Closes Python

like so .......

int main(int argc,char *argv[])
{

int count = 0;
PyObject *pmod;

while ( count < 10)
{

/*
** Initialize Python
*/

Py_Initialize();
printf("\nOpen Python ---- >");

pmod = PyImport_ImportModule("test");

Py_DECREF(pmod);

/*
** Close Python
*/

Py_Finalize();
printf("\n<---- Closed Python");
/*
** Do this 10 times !
*/
count++;

}
getchar();
return(0);

}

and thats it !

The script it calls is test.py its very simple , it imports numarray
and then returns. like so .......

-----------------------
test.py
-----------------------
#Imports
from numarray import *

def test_func():
return (99)
-----------------------
end of file
-----------------------
The first time it is called from my C code
it all works fine ! ( but only the first time ! )

In the second iteration above test .c crashes


From: http://www.pfdubois.com/numpy/html2/numpy-13.html

************************************************** ***********************
The Numeric installation process installed arrayobject.h in a subdirectory
Numeric in your Python include path, so you should include it this way:

#include "Numeric/arrayobject.h"
Is your C extension using Numeric blowing up? Maybe you didn't call
import_array(). If the extension is not in a single file, also define
PY_ARRAY_UNIQUE_SYMBOL.
In addition to including arrayobject.h , the extension must call import_array()
in its initialization function, after the call to Py_InitModule() . This call
makes sure that the module which implements the array type has been imported,
and initializes a pointer array through which the NumPy functions are called.
If you forget this call, your extension module will crash on the first call to
a NumPy function.

************************************************** ***********************

This referst to Numeric, but I'm sure the same issue exists with Numarray (I
still use Numeric, so I don't know the details with numarray).

cheers,

f
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Anand K Rayudu | last post by:
Hi All, I have one problem with embedding python into my application. on HP-UX11 i created my application with linking libPython2.3.a And with my product i supply all extension dlls and with...
0
by: Axel Diener | last post by:
I embed python interpreters in a C++ program. For each script to execute I create a new interpreter. In this environment I can use the win32 extensions only one time. Here is a little piece of...
23
by: Robey Holderith | last post by:
Anyone know a good way to embed python within python? Now before you tell me that's silly, let me explain what I'd like to do. I'd like to allow user-defined scriptable objects. I'd like to...
4
by: Alicia Haumann | last post by:
I accidentally sent this to webmaster@python.org, so this could be a duplicate if "webmaster" forwards it to this list. :{ Hi, there. Thanks for any help that can be offered. I've been...
1
by: amit | last post by:
Hello, I am currently studying how to embedd python. I am developing a graphical C++ application. My goal is to embedd python script that will control some kind of animation. I have some...
1
by: Tommy Nordgren | last post by:
I want to write an application that embeds and extends (at least) the Python and Perl interpreters. Now i want to find as much as possible about the Python tools used for extending and embedding...
4
by: adsheehan | last post by:
Hi, I am embedding Python into a multi-threaded C++ application running on Solaris and need urgent clarification on the embedding architecture and its correct usage (as I am experience weird...
1
by: freesteel | last post by:
I have posted about this problem before. SInce then I found a much better article to help with embedding python in a multithreaded application: http://www.linuxjournal.com/article/3641 I...
1
by: Benke | last post by:
Hello, I'm quite new to Python and embedding python in c++. I'm trying to write a function that i can use to call a python function. It should take 3 arguments, the name of the python file, the...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.