0

I tried to initialize QGIS from a standalone script, but it's giving the error (find in an image). enter image description here

I reinstalled, but the same issue occurred.

code:

from qgis.core import *

QgsApplication.setPrefixPath(r"C:\Program Files\QGIS 3.12", True)
qgs = QgsApplication([], False)
qgs.initQgis()
vlayer = QgsVectorLayer(path_to_airports_layer, "Airports layer", "ogr")
QgsProject.instance().addMapLayer(vlayer)
qgs.exitQgis()

How can I initialize correctly?

4
  • 1
    Please remember to always include the exact error message in the body of the Question as text. Images can't be indexed for search. Our purpose is to compile answers to GIS questions; hiding the question from others in effect hides the answer, and therefore discourages answering the question.
    – Vince
    Commented Jul 17, 2020 at 12:20
  • 1
    Under Windows OS you need to start python with correct environment. You can use a batch-file to do this. Read here: gis.stackexchange.com/questions/322195/… Commented Jul 17, 2020 at 13:00
  • @AndreasMüller I used the batch file as mentioned in an answer. code is running without any error but qgis application is not opening Commented Jul 18, 2020 at 8:09
  • You can't open QGIS this way, you'll be able to use QGIS-Elements that way. Make sure to read the Pyqis-Cookbook from the QGIS-Website! Commented Jul 18, 2020 at 8:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.