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.


from qgis.core import *

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

How can I initialize correctly?

  • 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 Jul 17 '20 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/… – Andreas Müller Jul 17 '20 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 – Velugoti Venkateswarlu Jul 18 '20 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! – Andreas Müller Jul 18 '20 at 8:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.