0

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?

Further notes:

  • 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.

PyQGIS errors

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.

0

1 Answer 1

1

I just tried the first steps of that tutorial using a OSGEO4W shell- I did:

set PYTHONPATH=c:\OSGeo4W64\apps\qgis-ltr\python

then

python

which gave:

    Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit 
(AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from qgis.core import *
    >>>

I don't have idle installed on that machine so I can't test it but I would try uninstalling and reinstalling QGIS and not changing the sys.path at all.

2
  • Thanks for your help Ian. I uninstalled QGIS, installed OSGeo4W and run the rules above in a cmd shell, but I still get the DLL error... Mar 2, 2020 at 15:00
  • Did another test in the OSGeo4W shell like you said: when I first run py3_env en then python3, I get the python console to start but when I run the qgis.core command I get the error: "No module named qgis" Mar 2, 2020 at 15:11

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.