Mapnik Shapefile datasource runtime error

1.1k views Asked by At

I am new to manpnik, facing similar problem. mapnik throws runtime error message every time I try to compile a sample code from python geospatial dev book. here's the root of the problem.

datasource = mapnik.Shapefile(file="world_borders.shp")
polygonLayer = mapnik.Layer("Polygons")
polygonLayer.datasource = datasource
polygonLayer.styles.append("polygonStyle")

error message
Traceback (most recent call last):
  File "createExampleMap.py", line 45, in <module>
    datasource = mapnik.Shapefile(file="world_borders.shp")
  File "C:\Python27\lib\site-packages\mapnik\__init__.py", line 341, in Shapefile
    return CreateDatasource(keywords)
RuntimeError: Could not create datasource for type: 'shape'


I'd appreciate help from anyone thanks
1

There are 1 answers

1
Alexander Pavlov On

I had this error message, too. For me it was caused by my moving the /site-packages/mapnik dir out of the Mapnik tree.

Assuming you are on Windows, you might want to check your paths are sane:

  1. start a command prompt in your demo/python folder and type PATH
    check that your lib folder is in the path

  2. start python from the same dir and say

    from mapnik import paths
    paths.mapniklibpath
    

    this should output your lib folder, e.g. 'c:\\mapnik-v2.2.0\\lib'

I placed Mapnik's site-packages in my Python's Lib dir, which screwed up mapnik.paths.