2

I am trying to start using Python with QGIS but I cannot get Python to work right. When I try import qgis.code in the python shell, I get this:

Traceback (most recent call last): File "<pyshell#0>", line 1, in import qgis.core ModuleNotFoundError: No module named 'qgis'

Then I go into Terminal and try this: export PYTHONPATH=/Applications/QGIS.app/Contents/Resources/python But my error message stays the same. Interestingly, if I try running python from Terminal and try to import qgis again, I get a different error code:

Traceback (most recent call last): File "", line 1, in File "/Applications/QGIS.app/Contents/Resources/python/qgis/core/__init__.py", line 25, in from qgis._core import * ImportError: dlopen(/Applications/QGIS.app/Contents/Resources/python/qgis/_core.so, 2): Library not loaded: @rpath/qgis_core.framework/Versions/3.18/qgis_core Referenced from: /Applications/QGIS.app/Contents/Resources/python/qgis/_core.so Reason: image not found

I have two versions of Python on my computer (Mac) which has caused so many problems for me; could that be the problem? How do I fix this? I tried following this: QGIS - ModuleNotFoundError but I don't know where to go from there. I am a programming noob so I don't even know what to fix there.

1
  • I ran in a similar issue, this question suggests that it is difficult. Also, the Qgis documentation is quite complex. So far, I have always used python scripts from within Qgis, which works, but outside I haven't figured it out yet. For different Python versions, I'd suggest Conda. Good luck!
    – Fee
    Commented May 5, 2021 at 0:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.