1

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)

2

I had the same problem. Following this thread, I made it work by setting QT_QPA_PLATFORM_PLUGIN_PATH in bash (e.g. from Terminal: nano ~/.bash_profile and add the line below).

export QT_QPA_PLATFORM_PLUGIN_PATH=/Applications/QGIS3.app/Contents/Plugins

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.