[Python-Dev] Demo/embed causes 'import site' failure

M.-A. Lemburg mal@lemburg.com
Mon, 10 Jul 2000 17:44:39 +0200


Guido van Rossum wrote:
> 
> (There's a linux question at the bottom.)
> 
> > > I decided to build the simple embedding demo in Demo/embed/.  After
> > > fixing the Makefile (checkins coming), I ended up with one problem:
> > > the 'import site.py' failed error.  When using -v I get this traceback:
> > >
> > > 'import site' failed; traceback:
> > > Traceback (most recent call last):
> > >   File "/usr/local/lib/python2.0/site.py", line 146, in ?
> > >     sys.setdefaultencoding('ascii')
> > > LookupError: no codec search functions registered: can't find encoding
> > >
> > > Is there some part of the initialization that I'm forgetting?
> >
> > Looks like the 'import encodings' failed. Could you check this
> > with -vv ?
> 
> Thanks for the hint.  Seems I've got it nailed down: it's looking for
> the struct module:
> 
> [...]
> import codecs # precompiled from /usr/local/lib/python2.0/codecs.pyc
> # trying /usr/local/lib/python2.0/struct.so
> # trying /usr/local/lib/python2.0/structmodule.so
> # trying /usr/local/lib/python2.0/struct.py
> # trying /usr/local/lib/python2.0/struct.pyc
> # trying /usr/local/lib/python2.0/plat-linux2/struct.so
> # trying /usr/local/lib/python2.0/plat-linux2/structmodule.so
> # trying /usr/local/lib/python2.0/plat-linux2/struct.py
> # trying /usr/local/lib/python2.0/plat-linux2/struct.pyc
> # trying /usr/local/lib/python2.0/lib-tk/struct.so
> # trying /usr/local/lib/python2.0/lib-tk/structmodule.so
> # trying /usr/local/lib/python2.0/lib-tk/struct.py
> # trying /usr/local/lib/python2.0/lib-tk/struct.pyc
> # trying /usr/local/lib/python2.0/lib-dynload/struct.so
> # trying /usr/local/lib/python2.0/lib-dynload/structmodule.so
> 'import site' failed; traceback:
> Traceback (most recent call last):
>   File "/usr/local/lib/python2.0/site.py", line 146, in ?
>     sys.setdefaultencoding('ascii')
> LookupError: no codec search functions registered: can't find encoding
> [...]
> 
> But the bizarre thing is that the last file it tries
> (/usr/local/lib/python2.0/lib-dynload/structmodule.so) actually
> exists!!!
> 
> OK, so there's code masking the ImportError in import_encodings() in
> codecs.c.  I disabled that (hmm, maybe this should be disabled
> automatically when -v is used!).

Hard to do since the setting of the verbosity flag is not
available to Python code.

>  Now I get this traceback:
> 
> Traceback (most recent call last):
>   File "/usr/local/lib/python2.0/site.py", line 146, in ?
>     sys.setdefaultencoding('ascii')
>   File "/usr/local/lib/python2.0/encodings/__init__.py", line 30, in ?
>     import codecs,aliases
>   File "/usr/local/lib/python2.0/codecs.py", line 10, in ?
>     import struct,types,__builtin__
> ImportError: /usr/local/lib/python2.0/lib-dynload/structmodule.so: undefined symbol: PyString_Type
> 
> OK, I've managed to fix it by a change to the way I build Python: I'm
> now linking the struct module (and everything in Setup up to and
> including _codecs) statically.
> 
> But I guess what's really missing is some kind of flag that tells the
> linker to export all symbols in the libpython2.0.a file...  Is there a
> way?  (I feel so stupid!)

From man ld:

       -E

       -export-dynamic
              When  creating  an ELF file, add all symbols to the
              dynamic symbol table.  Normally, the dynamic symbol
              table contains only symbols which are used by a dy­
              namic object.  This option is needed for some  uses
              of dlopen.

(Not sure whether this is what you're looking for, though.)

-- 
Marc-Andre Lemburg
______________________________________________________________________
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/