0

Following the PyQGIS Developer Cookbook to use PyQGIS in standalone scripts. Fixed the initial errors by setting the PYTHONPATH and DYLD_PYTHON_PATH to the appropriate folders but am now faced with the error:

ImportError: dlopen(/Applications/QGIS3.4.app/Contents/MacOS/../Resources/python/PyQt5/QtCore.so, 2): Library not loaded: @executable_path/../Frameworks/QtCore.framework/QtCore
  Referenced from: /Applications/QGIS3.4.app/Contents/Resources/python/PyQt5/QtCore.so
  Reason: image not found

It loads fine in the QGIS interpreter, and I ran sys.path in QGIS, then ran sys.path.append in my external interpreter for every path that QGIS is connected with from the sys.path results, but no luck. I've found the QtCore.so image but directing the path to that file also doesn't work.

Does anybody know how to get around this issue?

2

Usage of @executable_path is the limitation of the current all-in-one MacOS QGIS bundle.

Your executable must be in /Applications/QGIS3.4.app/Contents/MacOS/bin folder so the @executable_path/../Frameworks/QtCore.framework/QtCore is expanded to /Applications/QGIS3.4.app/Contents/MacOS/Frameworks/QtCore.framework/QtCore where the library exists

Do you run the script with /Applications/QGIS3.4.app/Contents/MacOS/bin/python3?

see this link for explanation and you can use otool -L <library/executable> to list loaded libraries

1
  • 1
    Brilliant! Running the script in /Applications/QGIS3.4.app/Contents/MacOS/bin/python3 works fine. Frustrating to spend all that time trying to connect paths when the answer was to use the correct QGIS python version in an external interpreter. Thanks so much! – Rob Mar 27 '20 at 19:05

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.