Skip to main content
Bumped by Community user
added mac tag
Link
Kadir Şahbaz
  • 78k
  • 57
  • 257
  • 404
Source Link

Cannot run external scripts with QGIS 3.2 on Mac OS X 10.12

I am trying to move some automation out of the GUI and into some external python scripts, and I am having a challenge getting a script to run in Terminal.

I have a fully functioning install of QGIS 3.2, can run commands in the console in app etc.

But trying even a basic hello world crashes when I try to run it: the following:

from qgis.core import *

QgsApplication.setPrefixPath("/Applications/QGIS3.app/Contents/MacOS", True)
qgs = QgsApplication([], False)
qgs.initQgis()
qgs.exitQgis()

produces this error:

This application failed to start because it could not find or load the Qt platform plugin "cocoa" in "".

Reinstalling the application may fix this problem.
Abort trap: 6

Does anyone have a workaround or specific list of bash_profile variables to have things set up correctly? Do I need to import Qt or similar in the script (this was pulled directly from the QGIS Documentation site)