I am stuck trying to code a custom application with QGIS and Python. I have some Python knowledge but I am quite new to QGIS. I tried the intro of the cookbook: Running Custom Applications.
Now while I run the code from IDLE I constantly get an error message saying:
File "H:\pathto\qgis_test.py", line 1, in <module> from qgis.core import * File "C:\Program Files\QGIS 3.10\apps\qgis\python\qgis\core\__init__.py", line 25, in <module> from qgis._core import * ImportError: DLL load failed while importing _core: Cannot find module..
I guess this has to do with the environment path variables, I tried alot but can't seem to fix it. From another post out here I tried the sys.path paths, here's mine:
C:\Program Files\QGIS 3.10\apps\qgis\python C:\Users\myname\AppData\Roaming\QGIS\QGIS3\profiles\default\python C:\Users\myname\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins C:\Program Files\QGIS 3.10\apps\qgis\python\plugins C:\Program Files\QGIS 3.10\apps\Python37 C:\Program Files\QGIS 3.10\apps\Python37\Scripts C:\Program Files\QGIS 3.10\bin\python37.zip C:\Program Files\QGIS 3.10\apps\Python37\DLLs C:\Program Files\QGIS 3.10\apps\Python37\lib C:\Program Files\QGIS 3.10\bin C:\Program Files\QGIS 3.10\apps\Python37\lib\site-packages C:\Program Files\QGIS 3.10\apps\Python37\lib\site-packages\win32 C:\Program Files\QGIS 3.10\apps\Python37\lib\site-packages\win32\lib C:\Program Files\QGIS 3.10\apps\Python37\lib\site-packages\Pythonwin C:\Users\myname\AppData\Roaming\QGIS\QGIS3\profiles\default\python C:\Users\myname\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\qgis2web C:\Users\myname\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins
Currently I set these system variables in PYTHONPATH, and in Path:
C:\Program Files\QGIS 3.10\apps\qgis C:\Program Files\QGIS 3.10\apps\qgis\python C:\Program Files\QGIS 3.10\bin C:\Program Files\QGIS 3.10\apps\qgis\bin C:\Program Files\QGIS 3.10\apps\Python37
I'm not sure if these are correct, but this gives me the mentioned error. Now if I add:
C:\Program Files\QGIS 3.10\apps\Python37\DLLs
to the PYTHONPATH(s), and try to open my script again in IDLE, it just does not open anymore.
Does anyone see the problem and how to fix this so I can run the script correctly?
- Before this I got some other errors, fixed some by installing PyQt, Python 3.8.2 (64bit) besides Python 3.7.2 (32bit) which I ran before.
- I haven't installed OSGeo4W separately, just QGIS3.10, not sure what that OSGeo4W is exactly, I'm just trying to get the Python part to work.
I am still stuck. Here is an image where I tried different tests, in a OSGeo4W shell and a Windows shell, where I get different errors. As soon as I include a PATH the python shell won't even start anymore but without that path the shell doesn't seem to know where to search for the modules so I get errors every time.