[Pythonmac-SIG] cyptes problem on MacOS X

Christopher Barker Chris.Barker at noaa.gov
Tue Dec 12 01:21:15 CET 2006

Russell E. Owen wrote:
> I've been trying out ctypes (from MacPython 2.5) on MacOS X on a PPC Mac 
> and have run into a problem.

I'm no help here.

> On a related subject...assuming I can get this to work...does anyone 
> have any idea how the speed of ctypes relates to programming a python C 
> extension or using SWIG?

probably a bit better performance for ctypes -- swig does put a fair bit 
  between C and Python.

> This is mostly for use with NumPy and 
> interfacing python to C/C++-based heavy duty astronomical image 
> processing code.

In this case, you'll mostly  be passing large arrays back and forth -- I 
doubt the overhead of any wrapping technique will be noticeable.

That being the case, what you want is whatever is most comfortable for 

> We'll mostly be interfacing to C++ so 
> I've considered trying out Boost, but it hasn't had an update in years 
> which worries me.

I'm pretty sure that someone has updated the boost array code for numpy, 
but I'm not sure where to find that out. I'd ask on the numpy list - if 
no one there is using it, I'd call it risky. You might also look at the 
C++-sig -- there's been discussion of this there recently.

pyrex is another candidate worth looking at. There should be examples on 
the scipy Wiki.

This has been my way of thinking:

If you have a substantial existing C/C++ library, particularly one that 
is undergoing continued development and needs to be used with both c/C++ 
and Python code: use SWIG (or maybe SIP, but I've never heard of that 
being used with numpy)

If you have a single dll (or *.so, etc) or small lib, use ctypes.

If you have ONLY the dll, and not source code, definitely use ctypes!

If you're developing extensions just for use with Python, use pyrex or 
boost. Prefer pyrex is it's C, boost if it's C++. Boost gets even more 
compelling if you are using other boost libs for your C++ stuff.

Cxx maybe worth a look-see. I think it's being used for matplotlib, so 
there must be a way to so numpy with it.


It would be great it we could put a note like this, with more detail, on 
the Scipy Wiki. Maybe you could do that when you learn more.

(oh, and be sure to check the Scipy Wiki. there is some stuff there already)


Christopher Barker, Ph.D.

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov

More information about the Pythonmac-SIG mailing list