TransWikia.com

PyQGIS: DLL load failed while importing _core. Environment path?

Geographic Information Systems Asked by pyqgis_newbie on December 1, 2020

I would like to ask for help because I got stuck trying to code a custom application with QGIS and Python. I got 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:pathtoqgis_test.py", line 1, in <module>
    from qgis.core import *
  File "C:Program FilesQGIS 3.10appsqgispythonqgiscore__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 FilesQGIS 3.10appsqgispython
C:UsersmynameAppDataRoamingQGISQGIS3profilesdefaultpython
C:UsersmynameAppDataRoamingQGISQGIS3profilesdefaultpythonplugins
C:Program FilesQGIS 3.10appsqgispythonplugins
C:Program FilesQGIS 3.10appsPython37
C:Program FilesQGIS 3.10appsPython37Scripts
C:Program FilesQGIS 3.10binpython37.zip
C:Program FilesQGIS 3.10appsPython37DLLs
C:Program FilesQGIS 3.10appsPython37lib
C:Program FilesQGIS 3.10bin
C:Program FilesQGIS 3.10appsPython37libsite-packages
C:Program FilesQGIS 3.10appsPython37libsite-packageswin32
C:Program FilesQGIS 3.10appsPython37libsite-packageswin32lib
C:Program FilesQGIS 3.10appsPython37libsite-packagesPythonwin
C:UsersmynameAppDataRoamingQGISQGIS3profilesdefaultpython
C:UsersmynameAppDataRoamingQGISQGIS3profilesdefaultpythonpluginsqgis2web
C:UsersmynameAppDataRoamingQGISQGIS3profilesdefaultpythonplugins

Currently I set these system variables in PYTHONPATH, and in Path:

C:Program FilesQGIS 3.10appsqgis
C:Program FilesQGIS 3.10appsqgispython
C:Program FilesQGIS 3.10bin
C:Program FilesQGIS 3.10appsqgisbin
C:Program FilesQGIS 3.10appsPython37

I’m not sure if these are correct, but this gives me the mentioned error. Now if I add:

C:Program FilesQGIS 3.10appsPython37DLLs

to the PYTHONPATH(s), and try to open my script again in IDLE, it just not opens anymore?

Does anyone see the problem and how to fix this so I can run the script correctly? I would really appreciate it. Thanks in advance!

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.

2 Answers

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

set PYTHONPATH=c:OSGeo4W64appsqgis-ltrpython

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.

Answered by Ian Turton on December 1, 2020

PyQGIS errors

Hello all, 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...

Answered by pyqgis_newbie on December 1, 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