0

I want Gunicorn to talk with TileStache via WSGI. But when I run this command...

gunicorn "TileStache:WSGITileServer('/var/osm/bright/project/OSMBright4/tilestache.cfg')"

...I get these errors:

2013-03-30 23:02:41 [14300] [INFO] Starting gunicorn 0.17.2
2013-03-30 23:02:41 [14300] [INFO] Listening at: http://127.0.0.1:8000 (14300)
2013-03-30 23:02:41 [14300] [INFO] Using worker: sync
2013-03-30 23:02:41 [14305] [INFO] Booting worker with pid: 14305
Error loading Tilestache config:
2013-03-30 23:02:41 [14305] [ERROR] Exception in worker process:
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 485, in spawn_worker
    worker.init_process()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 100, in init_process
    self.wsgi = self.app.wsgi()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/base.py", line 103, in wsgi
    self.callable = self.load()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 25, in load
    return util.import_app(self.app_uri)
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/util.py", line 381, in import_app
    app = eval(obj, mod.__dict__)
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/TileStache/__init__.py", line 373, in __init__
    self.config = parseConfigfile(config)
  File "/usr/local/lib/python2.7/dist-packages/TileStache/__init__.py", line 166, in parseConfigfile
    return Config.buildConfiguration(config_dict, dirpath)
  File "/usr/local/lib/python2.7/dist-packages/TileStache/Config.py", line 217, in buildConfiguration
    config.layers[name] = _parseConfigfileLayer(layer_dict, config, dirpath)
  File "/usr/local/lib/python2.7/dist-packages/TileStache/Config.py", line 441, in _parseConfigfileLayer
    layer.provider = _class(layer, **provider_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/TileStache/Mapnik.py", line 81, in __init__
    engine = mapnik.FontEngine.instance()
NameError: global name 'mapnik' is not defined
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 485, in spawn_worker
    worker.init_process()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 100, in init_process
    self.wsgi = self.app.wsgi()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/base.py", line 103, in wsgi
    self.callable = self.load()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 25, in load
    return util.import_app(self.app_uri)
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/util.py", line 381, in import_app
    app = eval(obj, mod.__dict__)
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/TileStache/__init__.py", line 373, in __init__
    self.config = parseConfigfile(config)
  File "/usr/local/lib/python2.7/dist-packages/TileStache/__init__.py", line 166, in parseConfigfile
    return Config.buildConfiguration(config_dict, dirpath)
  File "/usr/local/lib/python2.7/dist-packages/TileStache/Config.py", line 217, in buildConfiguration
    config.layers[name] = _parseConfigfileLayer(layer_dict, config, dirpath)
  File "/usr/local/lib/python2.7/dist-packages/TileStache/Config.py", line 441, in _parseConfigfileLayer
    layer.provider = _class(layer, **provider_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/TileStache/Mapnik.py", line 81, in __init__
    engine = mapnik.FontEngine.instance()
NameError: global name 'mapnik' is not defined
2013-03-30 23:02:41 [14305] [INFO] Worker exiting (pid: 14305)
2013-03-30 23:02:41 [14300] [INFO] Shutting down: Master
2013-03-30 23:02:41 [14300] [INFO] Reason: Worker failed to boot.

Does anyone know what it means?

Martin Atkins
  • 62,420
  • 8
  • 120
  • 138
Ivar
  • 4,344
  • 6
  • 38
  • 53

2 Answers2

2

Do you have python-mapnik installed? The error appears to be in the configuration of TileStache and mapnik rather than gunicorn or WSGI. If you look at TileStache/Mapknik.py (I am looking here: https://github.com/migurski/TileStache/blob/master/TileStache/Mapnik.py), you see that the initial import of mapnik passes on the error:

try:
    import mapnik
except ImportError:
    # can still build documentation
    pass

but that will cause problems in line 81 when mapnik is expected to be there. So, make sure you apt-get install python-mapnik or otherwise ensure mapnik is in your Python path.

Karmel
  • 3,452
  • 2
  • 18
  • 11
  • I have `python-mapnik2` installed, I guess that's the same. But Mapnik isn't in `/usr/local/lib/python2.7/dist-packages/`. Although, a search among my installed packages gives me `libmapnik2-2.2`, `mapnik-utils` and `python-mapnik2`. – Ivar Mar 31 '13 at 08:38
  • If you go to the python command line and try to `import mapnik`, does it work? – Karmel Mar 31 '13 at 15:31
  • I found it out, see my answer. :-) – Ivar Apr 01 '13 at 11:01
0

Problem solved.

It came up, as Karmel mentioned, that the problem lay in Mapnik and TileStache, and not Gunicorn.

After some research I found out that there has been changes of the python module name through the different versions; it was mapnik until version 2.0 when it changed to mapnik2, and then back to mapnik again at version 2.1. And obviously it appeared that I had installed version 2.0.

I suppose I just could have changed to import mapnik2 in TileStache/mapnik.py, but I thought it would be more future friendly to uninstall Mapnik and then build it from source instead. It took a while, but definitely worth it.

A big thanks to Karmel for putting me at the right track!

Community
  • 1
  • 1
Ivar
  • 4,344
  • 6
  • 38
  • 53