Accessing dyn modules from embedded python

Jeff Davis jdavis at empires.org
Wed Oct 9 04:09:47 EDT 2002


I think you need to link the executable with the python library.

Python only searches a certain set of directories, so you need to provide 
the PYTHONPATH so that it searches the right one.

And if you want to deploy the app along with libraries, I would just copy 
the libraries as well as your code. Just put them all in the right 
directory and you shouldn't have a problem.

Regards,
        Jeff Davis


> 
> Hi.
> 
> I'm trying to embed Python into my application.
> The smoke test already works, I've managed to call a pure python function
> from my C++ code.
> 
> But, an error occurred when I tried this:
> 
> # -- my python module used by C++ program --
> def translate(data):
> return unicode(data, 'koi8-r').encode('cp1251')
> 
> $ PYTHONPATH=`pwd` ./translator
> Traceback (most recent call last):
>   File "/home/max/projects/e2u/express2u.py", line 2, in ?
>     import codecs
>   File "/usr/lib/python2.2/codecs.py", line 10, in ?
>     import struct, __builtin__
> ImportError: /usr/lib/python2.2/lib-dynload/struct.so: undefined symbol:
> PyString_Type Aborted (core dumped)
> 
> 
> The translator is build with
> 
> PY_CONFIG = /usr/lib/python2.2/config
> PY_CFLAGS = -I/usr/include/python2.2/ -g
> PY_LDFLAGS = -lpthread -ldl -lutil
> 
> translator: translator.cpp TranslationService.o
> $(CXX) $(PY_LDFLAGS) -g -o $@ $^ $(PY_CONFIG)/libpython2.2.a
> 
> TranslationService.o: TranslationService.cpp TranslationService.h
> $(CXX) $(PY_CFLAGS) -Wall -c TranslationService.cpp -o
> TranslationService.o
> 
> 
> 
> Another related question:  I want to deploy my C++ app with embedded
> Python on machines where no Python is installed. How should bundle other
> modules I'm interested in (like locale, codecs, etc.)?
> 
> 
> Btw, If I doesn't specify PYTHONPATH the translator can't find the
> module. Why is this?
> 




More information about the Python-list mailing list