Python 共享库 - Cheetah namemapper.so 未找到

发布于 2024-10-05 06:40:16 字数 1727 浏览 6 评论 0原文

我使用 Python Cheetah 进行模板生成,但无法让它使用已安装的已编译的 _namemapper.so 库。我在安装了 Python 2.4 的 CentOS 5.4 上运行,使用 Cheetah 2.4.3。我一生都无法让 Cheetah 使用我在安装过程中构建的 _namemapper.so 文件:

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's 
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.

但是,我的共享库位于 NameMapper 模块旁边:

$ 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

我尝试将此目录添加到 /etc/ld.so.conf.d/python-cheetah.conf 中,但找不到 _namemapper.so 共享库。

有什么想法吗?

已解决

谢谢@alex-b。结果我在 32 位机器上编译了 Cheetah,并尝试在 64 位机器上加载共享库。噢!

>>> 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

然后我遇到了下一个问题:

>>> 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

事实证明 Cheetah 在 Python <= 2.6 上运行得不太好,所以我将升级。

I'm using Python Cheetah for template generation and I can't get it to use the compiled _namemapper.so library that is installed. I am running on CentOS 5.4 with Python 2.4 installed, using Cheetah 2.4.3. I cannot for the life of me get Cheetah to use the _namemapper.so file that I built during install:

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's 
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 have the shared library sitting right 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've tried adding this directory to /etc/ld.so.conf.d/python-cheetah.conf, and the _namemapper.so shared library is not found.

Any ideas?

SOLVED

Thanks @alex-b. Turns out I had compiled Cheetah on a 32-bit machine and was attempting to load the shared library on a 64-bit machine. D'oh!

>>> 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 next 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 doesn't work so well on Python <= 2.6, so I will be upgrading.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

狠疯拽 2024-10-12 06:40:16
  1. 调用脚本时,请确保 _namemapper.so 位于 sys.path 中的路径之一。可能是某些东西配置错误(可能是安装在某个地方的另一个 python,例如,在您的主目录中)。

    导入系统
    系统路径
    
  2. 如果库本身确实已加载,请尝试检查它的版本是否正确。 Cheetah 似乎尝试从 _namemapper 加载特定函数 (Utils/NameMapper.py:288):

    <前><代码>尝试:
    从_namemapper导入NotFound,valueForKey,valueForName,\
    valueFromSearchList、valueFromFrameOrSearchList、valueFromFrame
    C_VERSION = 真
    除了:
    C_VERSION = 假

    如果失败,C_VERSION 将设置为 False,从而向您发出此警告。尝试自己从_namemapper导入这些符号,可能是您的_namemapper.so版本错误。

  1. Make sure that _namemapper.so is in one of the paths in sys.path when your script is invoked. It's possible that something is misconfigured (can be another python installed somewhere, for example, in your home directory).

    import sys
    sys.path
    
  2. If the library itself is indeed loaded, try checking if it's of the correct version. It seems that Cheetah tries to load particular 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 is set to False, which gives you this warning. Try importing these symbols from _namemapper yourself, it may be that your _namemapper.so version is wrong.

夏末的微笑 2024-10-12 06:40:16

有时,使用 strace 打印开放调用以跟踪 Python 使用的搜索路径很有用。

例如。如果您尝试导入的模块的名称是 namemapper,则以下内容将显示搜索 namemapper 模块的路径。

strace -e open python -c 'import namemapper'

这可能会给您一些关于为什么您的模块没有被使用的线索。

编辑:更正了上面 strace 命令行中模块名称的拼写。

Sometimes it's useful to use strace to print out open calls to trace the search path used by Python.

eg. If the name of the module you're trying to import is namemapper, the following will show the paths searched 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: corrected spelling of module name in the strace command-line above.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文