[Qgis-user] Troubleshooting Python Script - QGIS library Import on Recent Versions on Mac OS X
Odom, Johnnie
JOdom at ecsdfl.us
Thu Aug 20 09:28:35 PDT 2026
Hello Everyone,
I am sorry to join the list with such a lengthy question.
I am having problems using QGIS in a Python script. This script previously
worked. My goal is to dynamically build maps. I am using Mac OS X (M2
processor) and have access to both QGIS 3.44 (installed via MacPorts) and
4.2 (installed from the QGIS website.)
I read the QGIS documentation on developing apps using QGIS and a few other
articles and then gradually began writing code. In the end I had a script
that could create a project, import layes in various formats, and run some
plugin operations against them. My code worked for several months and then
a few months ago it stopped working. I suspect an update to my Mac or to
the MacPorts QGIS was the cause, but I cannot get back to a good state.
So, my question is: Given the current state of QGIS on the Mac, what is the
best way to set my environment up to write standalone scripts incorporating
QGIS?
My issue, as far as I can tell, is that the main QGIS library either does
not import or crashes when I import it depending upon the QGIS installation.
Before trying to load qgis I import either PyQt5 (for 3.44) or PyQt6 (for
4.2)
Using python 3.12, 3.13, or 3.14 if I try to import from
/Applications/MacPorts/QGIS3.app/Contents/Resources/python/ (for version
3.44) then the program stops running after the "import qgis" statement but
it does not indicate that it has stopped -- it just never reaches the next
statement in the programming (i.e. print("I have imported qgis")).
If I switch to version 4.2 and import from
/Applications/QGIS-final-4_2_0.app/Contents/Resources/python3.12/site-packages/
with the same code, then I get a crash with the stack trace ending as
follows:
File
"/Applications/QGIS-final-4_2_0.app/Contents/Resources/python3.12/site-packages/qgis/core/__init__.py",
line 29, in <module>
from qgis._core import *
ImportError:
dlopen(/Applications/QGIS-final-4_2_0.app/Contents/Resources/python3.12/site-packages/qgis/_core.so,
0x0002): Library not loaded: @rpath/libpython3.12.dylib
Referenced from: <75DA0087-BE20-3D08-B088-B5B4500EE33B>
/Applications/QGIS-final-4_2_0.app/Contents/Resources/python3.12/site-packages/qgis/_core.so
Reason: no LC_RPATH's found
I understand that in the past you should only expect programming against a
QGIS application to work if you either used MacPorts or built it from
source. However, I thought that the Mac changes to version 4.x might have
changed the recommendation (and also MacPorts does not yet support 4.x). It
does not matter to me which version I program against, I just want to get
to a stable point.
Thank you for any pointers you can give.
Kind Regards,
Johnnie Odom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20260820/a73832a7/attachment.htm>
More information about the QGIS-User
mailing list