Embedding Python in a plugin

David Boddie davidb at mcs.st-and.ac.uk
Tue Jul 15 16:34:31 EDT 2003


Daniel Holth <dholth at fastmail.fm> wrote in message news:<h2GQa.1856$Mc.172386 at newsread1.prod.itd.earthlink.net>...
> Hello!  I am trying to embed Python into an xmms plugin using
> Debian/unstable/i386, gcc 3.3.1 and Python 2.2.3+.  The plugin is a shared
> library loaded by xmms.  The plugin is dynamically linked with the python
> library.

Sounds good so far!

> Running scripts works but when I try to import python extensions I get these
> kinds of errors:
> 
> Traceback (most recent call last):
>   File "<string>", line 1, in ?
>   File "/home/dholth/lib/python2.2/site-packages/xmmspy.py", line 12, in ?
>     import time
> ImportError: /usr/lib/python2.2/lib-dynload/time.so: undefined symbol:
> PyExc_IOError

Yes, I hate it when these crop up. I've also seen ones involving
_Py_NoneStruct or something similar.

> I'm using all the compiler options I can find!
> 
> /bin/sh ./libtool --mode=link gcc -Wall -I/usr/include/xmms
> -I/usr/include/gtk-1.2 -I/usr/include/glib-1.2 -I/usr/lib/glib/include -g
> -O2 -I/usr/include/python2.2 -I/usr/include/glib-1.2
> -I/usr/include/python2.2 -g -O2 -I/usr/include/python2.2   -o libxmmspy.la
> -rpath /usr/lib/xmms/General -module -avoid-version -Xlinker
> -export-dynamic xmmspy.lo  -lstdc++ -lpython2.2 -L/usr/lib -L/usr/X11R6/lib
> -lgtk -lgdk -rdynamic -lgmodule -lglib -ldl -lXi -lXext -lX11 -lm -lxmms
> 
> ... including "-Xlinker -export-dynamic" as suggested by distutils.

I think that you can probably remove some of those options and stick
with the "-Xlinker -export-dynamic" but you may need to use
"-Xlinker -R <path>" for runtime linking. Maybe -rpath handles that.
I'm a newcomer to this myself, so I'm sure I'll be corrected if I'm out of
line.

> How do I embed Python in an application where the main application has no
> knowledge of Python, only the dynamically loaded plugin does?  Which
> programs do this already?

These problems receive some attention in the Python FAQ and in the
Extending and Embedding section of the Python manual. Unfortunately, some
of the recommendations I've seen aren't workable if you don't have any control
over how the target application was built: using various options with dlopen,
for example.

Anyway, the problem you have at the top of this message can probably
be solved by linking against the time module, which is probably residing in

/usr/lib/python2.2/lib-dynload/time.so

or somewhere similar.

Good luck!

David
-- 
http://www.boddie.org.uk/david/Projects/




More information about the Python-list mailing list