2

I uninstalled arcmap and all existing python installations. Then I followed the instructions from https://www.youtube.com/watch?v=Chq9fTRKsHk&t=2s to install qgis and set the environment variables.

I'm attempting to run the script from the second video (https://www.youtube.com/watch?v=Y8JjvBKOCDk&list=PLzHdTn7Pdxs4AvkJeJwlyav2-at9QwKWR) which should launch a blank canvas.

from qgis.core import *
from qgis.gui import *
from PyQt4.QtCore import *
from PyQt4 import QtGui

app = QtGui.QApplication

QgsApplication.setPrefixPath("C:/OSGeo4W/apps/qgis", True)
QgsApplication.initQgis()

window = QtGui.QMainWindow()
window_frame = QtGui.QFrame(window) 11
window.setCentralWidget(window_frame)
frame_layout = QtGui.QGridLayout(window_frame)

canvas = QgsMapCanvas()
frame_layout.addWidget(canvas)

window.show()
app.exec_()

It's supposed to bring up a canvas but does not.

The error I'm getting is

Process finished with exit code -1073741819 (0xC0000005)

I don't know if the problem is in the environment variables or in the script. Any ideas?

2

Try editing your code with the following:

  • Replace app = QtGui.QApplication with app = QApplication([], True)
  • Move the above line after you have set your prefix path.
  • Add from PyQt4.QtGui import QApplication when importing PyQt4 modules
  • Remove 11 in the line window_frame = QtGui.QFrame(window) 11

Running the above works for me, here is the code I used:

from qgis.core import *
from qgis.gui import *
from PyQt4.QtCore import *
from PyQt4 import QtGui
from PyQt4.QtGui import QApplication

QgsApplication.setPrefixPath("C:/OSGeo4W/apps/qgis", True)
app = QApplication([], True)
QgsApplication.initQgis()

window = QtGui.QMainWindow()
window_frame = QtGui.QFrame(window)
window.setCentralWidget(window_frame)
frame_layout = QtGui.QGridLayout(window_frame)

canvas = QgsMapCanvas()
frame_layout.addWidget(canvas)

window.show()
app.exec_()

Result

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.