Python shared libraries - Cheetah namemapper.so not found

I use Python Cheetah to generate templates, and I cannot get it to use the compiled _namemapper.so library that is installed. I am running CentOS 5.4 with Python 2.4 installed using Cheetah 2.4.3. I can’t get Cheetah to use the _namemapper.so file that I created during installation during my life:

 Filling conf/asterisk/sip.conf.ect -> conf/asterisk/sip.conf ... /usr/lib64/python2.4/site-packages/Cheetah/Compiler.py:1508: UserWarning: You don't have the C version of NameMapper installed! I'm disabling Cheetah useStackFrames option as it is painfully slow with the Python version of NameMapper. You should get a copy of Cheetah with the compiled C version of NameMapper. 

However, I do have a shared library sitting next to the NameMapper modules:

 $ ls -ltr /usr/lib64/python2.4/site-packages/Cheetah/ | grep -i namemap -rw-r--r-- 1 root root 12376 Jul 1 20:17 NameMapper.py -rwxr-xr-x 1 root root 36982 Dec 1 09:55 _namemapper.so -rw-r--r-- 1 root root 12541 Dec 1 09:55 NameMapper.pyc 

I tried adding this directory to /etc/ld.so.conf.d/python-cheetah.conf and the _namemapper.so shared library _namemapper.so not found.

Any ideas?

solvable

Thanks @ alex-b. It turns out that I compiled Cheetah on a 32-bit machine and tried to load the shared library on a 64-bit machine. D'o!

 >>> from Cheetah._namemapper import NotFound Traceback (most recent call last): File "<stdin>", line 1, in ? ImportError: /usr/lib/python2.4/site-packages/Cheetah/_namemapper.so: wrong ELF class: ELFCLASS32 

Then I ran into the following problem:

 >>> from Cheetah._namemapper import NotFound Traceback (most recent call last): File "<stdin>", line 1, in ? ImportError: /usr/lib/python2.4/site-packages/Cheetah/_namemapper.so: undefined symbol: PyUnicode_FromFormat 

And it turns out that Cheetah does not work so well on Python <= 2.6, so I will update.

+4
source share
2 answers
  • Make sure _namemapper.so is in one of the paths in sys.path when calling the script. Maybe something is incorrectly configured (maybe another python is installed somewhere, for example, in your home directory).

     import sys sys.path 
  • If the library itself is really loaded, try checking its correct version. Cheetah seems to be trying to load certain functions from _namemapper (Utils / NameMapper.py: 288):

     try: from _namemapper import NotFound, valueForKey, valueForName, \ valueFromSearchList, valueFromFrameOrSearchList, valueFromFrame C_VERSION = True except: C_VERSION = False 

    If this fails, C_VERSION set to False, which gives you this warning. Try importing these characters from _namemapper yourself, your version of _namemapper.so incorrect.

+2
source

It is sometimes useful to use strace to print open calls to track the search path used by Python.

eg. If the name of the module you are trying to import is namemapper, the following shows the paths that were searched for for the namemapper module.

 strace -e open python -c 'import namemapper' 

This may give you some clues as to why your module is not being used.

Edit: Fixed spelling of the module name on the strace command line.

+2
source

All Articles