473,405 Members | 2,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 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 1960
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
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,...
0
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...

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.