[Prophesy] C from Python Example
Rasmus Andersen
rasmus at jaquet.dk
Tue Jun 11 07:33:18 EST 2002
On Sat, Jun 08, 2002 at 11:06:12PM +0200, Daniel Phillips wrote:
> The example can be compiled, installed as a module, and executed using the
> script line:
>
> cc -shared -I/usr/include/python2.2 python2.c -o foo.so && \
> sudo cp foo.so /usr/lib/python2.2/lib-dynload/ && \
> python2.2 -c "import foo; print foo.bar('test')"
Doing this nets me 'ImportError: dynamic module does not define init
function (initfoo)'. (OK, I cheated and skipped the second line
(see below)).
I have before used SWIG (www.swig.org) sucessfully as C/Python integrator.
The v1.3 (newest, I think) I had on my system choked on some of your
C constructs, using the attached patch helped.
Also, I had to use an interface file to get SWIG to grok other stuff.
Also attached.
I am not pushing this in a serious way since you seem to be doing
without but I wanted to show what I needed to do.
>
> I verified that this example works in python 1.5, 2.1 and 2.2. The
> python2.2-dev package has to be installed to get the Python.h header file.
>
> I'd like to import the module without copying it to the lib-dynload
> directory, which is not a good way to develop because it requires root
> privilege, and anyway, it's an annoying extra step. I'm sure there's a way
> to do it, but I haven't found it yet.
>
This problem I did not have on python2.1 and python1.5 (solaris) and
python2.2 (linux).
Rasmus
More information about the Prophesy
mailing list