pythonredhatmapniktilestache

Global name 'mapnik' not defined when using Tilestache


I set up a TileStache server on Redhat, installing Mapnik 2.2 from source. However, Tilestache is giving me the following error:

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

Relevant Information:

Question:

Does anyone know what could be causing this? Thanks in advance!


Solution

  • It turns out the root of this problem is fairly common. The libmapnik shared library was not found.
    When I tried to import mapnik from the python console I received this error:

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

    Which led me to the answer here: https://github.com/mapnik/mapnik/wiki/InstallationTroubleshooting#the-libmapnik-shared-library-is-not-found

    Solution: Add '/usr/local/lib' to '/etc/ld.so.conf' and run ldconfig.