I am trying to create a standalone application of QGIS in PyCharm. My code is:
app = QgsApplication([], True)
app.setPrefixPath("usr/lib/qgis/plugins", True)
app.initQgis()
canvas = QgsMapCanvas()
canvas.setWindowTitle('Aeee')
canvas.enableAntiAliasing(True)
canvas.setCanvasColor(Qt.white)
layer = QgsVectorLayer('LineString?crs=epsg:4326', 'MyLine' ,"memory")
pr = layer.dataProvider()
linstr = QgsFeature()
geom = QgsGeometry.fromWkt("LINESTRING (1 1, 10 15, 40 35)")
linstr.setGeometry(geom)
pr.addFeatures([linstr])
layer.updateExtents()
QgsProject.instance().addMapLayer(layer)
canvas.setExtent(layer.extent())
canvas.setLayers([layer])
canvas.zoomToFullExtent()
canvas.freeze(True)
canvas.show()
canvas.refresh()
canvas.freeze(False)
canvas.repaint()
exitcode = app._exec()
QgsApplication.exitQgis()
And the error I get is:
QStandardPaths: XDG_RUNTIME_DIR points to non-existing path '/run/user/1000/snap.pycharm-professional', please create it with 0700 permissions.
QStandardPaths: XDG_RUNTIME_DIR points to non-existing path '/run/user/1000/snap.pycharm-professional', please create it with 0700 permissions.
Process finished with exit code 1
I supposed this problem is because of the application that is trying to access the qgis path and that it having a problem with privileges. My first clue is to change the folder permissions and ownership, but because I am new to Ubuntu and PyQGIS, I asked this question.
/usr/bin/qgis
. And if you are running this standalone outside of qgis, then you can't use theMapCanvas
Class.