0

My Python window crashes after running this script. I have tested and it stops specifically at the qgs.initQgis() line.

I think that something changed in qgis from QGIS 2.18 to QGIS 3.4 where I need to change something with the path, but I can't quite figure that out.

import sys
from qgis.core import *
from qgis.gui import *
import qgis.utils
from qgis.core import QgsApplication


qgis_path = "C:\\Program Files\\QGIS 3.4"
QgsApplication.setPrefixPath(qgis_path, True)
qgs = QgsApplication([], False)
qgs.initQgis()

project = QgsProject.instance()

project.read('C:\\Users\\annam\\Desktop\\test.qgz')

layer = QgsVectorLayer('C:\\Users\\annam\\Downloads\\waterbodies\\arcimports\\kerr_225.shp', 'name', 'ogr')

project.addMapLayer(layer)

project.write()

qgs.exitQgis()
Fran Raga
  • 7,838
  • 3
  • 26
  • 47
  • Your code works, look at this to help you, https://anitagraser.com/2019/03/03/stand-alone-pyqgis-scripts-with-osgeo4w/ and https://gis.stackexchange.com/a/289964/49538 – Fran Raga May 08 '19 at 10:09
  • I'm running this with Anaconda (so that I can input it in ArcPro) do you think this will make a difference? – ajspaghetti May 08 '19 at 18:40
  • I ended up running it through ArcPro, but used a batch file to launch the python from C:\OSGeoW4 to run that part of the script. – ajspaghetti May 09 '19 at 04:53

0 Answers0