使用Tilestach时未定义全局名称“mapnik”

2024-06-01 05:28:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我在Redhat上设置了一个TileStache服务器,从源代码处安装mapnik2.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/地图尼克.py,但我的来自TileStache/商品/供应商/地图索引.py. 在
  • 相关帖子:Gunicorn fails when using WSGI

问题:

有人知道是什么引起的吗?提前谢谢!在


Tags: inpyselfapplicationlibpackagesusr错误
2条回答

事实证明,这个问题的根源是相当普遍的。找不到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.conf销售订单'并运行ldconfig。在

…保持了2018年8月22日的流量,Mapnik 3和TileStache,但得到了几乎相同的错误。接受的答案对我没有帮助,而且在最近的版本中Mapnik Python bindings are installed separately。在

查看here,我可以从命令行运行,只需:

pip install mapnik

这样我就可以运行python解释器并导入mapnik。在

一个潜在的警告。Mapnik新闻页面提到pip安装使用了“pythonwheels”,如果您检查链接的页面,就会提到需要pip>;=1.4。您可以在命令行中使用pip version检查Pip,我的是pip7.1.2。所以大多数人都不关心这个问题。在

相关问题 更多 >