TransWikia.com

Loading PyQt5 modules from QGIS3/PyQGIS

Geographic Information Systems Asked by pat-s on November 25, 2020

I am trying to talk to the PyQGIS API for use in a 3rd party application using the offical .dmg image provided on the QGIS homepage.

After setting PYTHONPATH to /Applications/QGIS3.4.app/Contents/Resources/python and initializing everything as stated in https://docs.qgis.org/3.4/en/docs/pyqgis_developer_cookbook/intro.html#using-pyqgis-in-custom-applications, I am facing the following error when running from PyQt5.QtGui import or from qgis import *:

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

Looks like I need to set some linkers or similar?

Side facts:
– I have no problems when using the homebrew version of QGIS).
– I am on macOS 10.14.6 (Mojave)

One Answer

A solution is to add the QGIS app binaries to the path to replace MacOS Python3 with the embed QGIS Python3, so, as PYTHONPATH :

export PATH="/Applications/QGIS3.4.app/Contents/MacOS/bin:$PATH"

and if necessary, if the Qt platform can't load correctly, following this answer :

export QT_QPA_PLATFORM_PLUGIN_PATH=/Applications/QGIS3.4.app/Contents/PlugIns
export GDAL_DATA=/Applications/QGIS3.4.app/Contents/Resources/gdal

Answered by J. Monticolo on November 25, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP