4

I'm trying to execute the following code on a windows 7 system:

import qgis.core as qc
qgis_path = "C:\Program Files\QGIS Lyon\apps\qgis"
qc.QgsApplication.setPrefixPath(qgis_path, True)
qc.QgsApplication.initQgis()
print "Successfully Initialised"

The qc.QgsApplication.initQgis() command causes python to stop working. Can anyone help with the steps I need to diagnose this problem?

Some background:

  • I've tried a number of different combinations of forward slashes, escaped backslashes etc.for the path and still get the same error;
  • I've been developing the code (part of a larger application) on Linux, without problems;
  • A long time ago, I tested the code on Windows and it worked OK. At that time I had QGIS Dufour installed;
  • I suspect it may have something to do with having the correct environment variables set, but have been unable to find a definitive guide on which and how these variables need to be set.
6

It seems things changed to init PyQGIS but were not updated in the cookbook.

There is a discussion about the issue. Look at the bottom of the discussion mainly.

Be careful, it's only a hint. It may be related to your Windows path too (working on Linux mainly).

So, it should work with

from qgis.core import QgsApplication
qgis_path = "C:/Program Files/QGIS Lyon/apps/qgis"
QgsApplication.setPrefixPath(qgis_path, True)
qgs = QgsApplication(sys.argv, False)
qgs.initQgis()
  • 1
    You're welcome. Can you validate my answer as it seems to be the right one. Thanks – ThomasG77 Dec 8 '15 at 13:26

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.