在Windows上如何获取和安装Python 2.7的_namemapper.pyd
我在我的Windows系统上安装了Python 2.7和Cheetah。下面是我在尝试使用cheetah.template对象和.tmpl文件时遇到的错误。
from Cheetah.Template import Template
t = Template(file='home.tmpl')
C:\wamp\bin\Python27\lib\site-packages\Cheetah\Compiler.py:1509: UserWarning:
You don't have the C version of NameMapper installed! I'm disabling Cheetah's us
eStackFrames option as it is painfully slow with the Python version of NameMappe
r. You should get a copy of Cheetah with the compiled C version of NameMapper.
"\nYou don't have the C version of NameMapper installed! "
from Cheetah.Template import Template
t = Template(file='home.tmpl')
print t
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\wamp\bin\Python27\lib\site-packages\Cheetah\Template.py", line 1005,
in __str__
rc = getattr(self, mainMethName)()
File "_wamp_www_b121pyraw_b121pycheetah_home_tmpl.py", line 89, in respond
File "C:\wamp\bin\Python27\lib\site-packages\Cheetah\NameMapper.py", line 246,
in valueFromSearchList
_raiseNotFoundException(key, searchList)
File "C:\wamp\bin\Python27\lib\site-packages\Cheetah\NameMapper.py", line 167,
in _raiseNotFoundException
raise NotFound(excString)
Cheetah.NameMapper.NotFound: cannot find 'firstdivcontents'
我搜索了适用于Python 2.7的_namemapper.pyd文件,但没有找到。只找到了适用于2.6的文件。请问我需要降级到Python 2.6吗?还是有其他方法可以安装它?
另外,如果我找到了_namemapper.pyd,应该怎么安装它才能和Python一起使用呢?
3 个回答
-1
我复制了一份名为 namemapper 的 Python 文件,然后通过把文件的后缀从 _namemapper.pyd
改成 _namemapper.so
来解决了我的问题,结果一切都正常运作。
我不能说这样做是正确的做法,但对我来说确实有效。
-1
文件 C:\Python27\Lib\site-packages\Cheetah\Compiler.py
从第1506行开始,把以下几行代码前面加上#,这样就可以解决错误了。
# if not NameMapper.C_VERSION:
# if not sys.platform.startswith('java'):
# warnings.warn(
# "\nYou 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."
# )
3
pyd文件是通过编译与软件包一起提供的C语言文件生成的。这个过程在安装时进行,如果你手头有C语言编译器的话。如果没有的话,Python会提供一个备用方案。在某些情况下,有些软件包可能根本无法安装。
对于没有C语言编译器的Windows用户,解决办法是安装已经编译好的C语言二进制包。不过,Cheetah似乎没有这样的包:http://pypi.python.org/pypi/Cheetah/2.4.4
所以,你需要安装一个C语言编译器。听说MinGW是个不错的选择。
不过,我觉得这根本不是你的问题。你遇到的错误似乎和这个警告没有关系。
如果你能提供出错的代码,可能更熟悉Cheetah的人能告诉你哪里出错了。