I'd like to open a shapefile in a standalone PyQGis App. The App starts and runs without a problem but a get an false-Return in the isValid()-Function on the Layer and the Layer doesn't show up.
I tried this on two different shapefiles and did make sure that the filepath is correct.
Can anyone tell me is there is something wrong or missing in the code or how I can debug this problem any further?
import sys from PyQt4 import QtGui from qgis.core import * from qgis.gui import * from PyQt4.QtCore import * app = QtGui.QApplication(sys.argv) window = QtGui.QMainWindow() window.setGeometry(550, 550, 500, 300) window.setWindowTitle("Test Window") window_frame = QtGui.QFrame(window) window.setCentralWidget(window_frame) frame_layout = QtGui.QGridLayout(window_frame) canvas = QgsMapCanvas() frame_layout.addWidget(canvas) filepath = "/home/stefan/testlayer/test.shp" layer = QgsVectorLayer(filepath, "testlayer", "ogr") QgsMapLayerRegistry.instance().addMapLayer(layer) if not layer.isValid(): print "Layer not valid" canvas_layer = QgsMapCanvasLayer(layer) canvas.setLayerSet([canvas_layer]) canvas.zoomToFullExtent() window.show() sys.exit(app.exec_())