Skip to main content
 首页 » 编程设计

python之使用 Tilestache 时未定义全局名称 'mapnik'

2025年05月04日24luoye11

我在 Redhat 上设置了一个 TileStache 服务器,从源代码安装了 Mapnik 2.2。但是,Tilestache 给我以下错误:

Traceback (most recent call last): 
  File "/usr/lib64/python2.6/site-packages/gevent/pywsgi.py", line 508, in handle_one_response 
    self.run_application() 
  File "/usr/lib64/python2.6/site-packages/gevent/pywsgi.py", line 494, in run_application 
    self.result = self.application(self.environ, self.start_response) 
  File "/usr/lib/python2.6/site-packages/TileStache/__init__.py", line 381, in __call__ 
    status_code, headers, content = requestHandler2(self.config, path_info, query_string, script_name) 
  File "/usr/lib/python2.6/site-packages/TileStache/__init__.py", line 254, in requestHandler2 
    status_code, headers, content = layer.getTileResponse(coord, extension) 
  File "/usr/lib/python2.6/site-packages/TileStache/Core.py", line 414, in getTileResponse 
    tile = self.render(coord, format) 
  File "/usr/lib/python2.6/site-packages/TileStache/Core.py", line 500, in render 
    tile = provider.renderTile(width, height, srs, coord) 
  File "/usr/lib/python2.6/site-packages/TileStache/Goodies/Providers/MapnikGrid.py", line 72, in renderTile 
    self.mapnik = mapnik.Map(0, 0) 
NameError: global name 'mapnik' is not defined 

相关信息:

  • 其他帖子建议将“import mapnik”更改为“import mapnik2 as mapnik”。但我得到了同样的错误信息。
  • 其他帖子来自 TileStace/Mapnik.py,但我的来自 TileStache/Goodies/Providers/MapnikGrid.py。
  • 相关帖子:Gunicorn fails when using WSGI

问题:

有谁知道这可能是什么原因造成的?提前致谢!

请您参考如下方法:

事实证明,这个问题的根源相当普遍。找不到 libmapnik 共享库。
当我尝试从 python 控制台导入 mapnik 时,我收到了这个错误:

>>> import mapnik 
Traceback (most recent call last): 
  File "<stdin>", line 1, in <module> 
  File "/usr/lib64/python2.6/site-packages/mapnik/__init__.py", line 69, in <module> 
    from _mapnik import * 
ImportError: libmapnik.so.2.2: cannot open shared object file: No such file or directory  

这让我得到了答案: https://github.com/mapnik/mapnik/wiki/InstallationTroubleshooting#the-libmapnik-shared-library-is-not-found

解决方案: 将“/usr/local/lib”添加到“/etc/ld.so.conf”并运行 ldconfig。