Opened 5 months ago

Last modified 3 months ago

#735 new defect

PyQt5 can't find DLL

Reported by: Andreas Müller Owned by: osgeo4w-dev@…
Priority: major Component: Package
Version: Keywords:
Cc:

Description (last modified by jef)

I'm running qgis-ltr 3.22. When I try to import from PyQt5, I get the error below:

    from PyQt5.QtCore import QSettings
    Traceback (most recent call last):
       File "<stdin>", line 1, in <module>
    ImportError: DLL load failed while importing QtCore: Das angegebene Modul wurde nicht gefunden.

May be I'm missing something, so I can't find QtCore.dll in my install for example.

Change History (8)

comment:1 by jef, 5 months ago

Not reproducable here. The QtCore module file is called QtCore.pyd and the corresponding Qt DLL Qt5Core.dll

Last edited 5 months ago by jef (previous) (diff)

comment:2 by Andreas Müller, 5 months ago

If I use the Python Console inside QGIS, it works, calling python-qgis-ltr.bat on the OSGeo4w-Shell I get the error. PATH and variables all look fine.

comment:3 by jef, 5 months ago

Still can't reproduce. Running python-qgis-ltr.bat from OSGeo4W shell in a fresh install of qgis-ltr:

run o-help for a list of available commands
C:\OSGeo4W>python-qgis-ltr
Python 3.9.5 (tags/v3.9.5:0a7dcbd, May  3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from PyQt5.QtCore import QSettings
>>> quit()

C:\OSGeo4W>type foo.py
from PyQt5.QtCore import QSettings

C:\OSGeo4W>python-qgis-ltr foo.py

C:\OSGeo4W>

comment:4 by jef, 5 months ago

Description: modified (diff)

comment:5 by Andreas Müller, 5 months ago

Thank you much, Jef, I did a fresh install and now both QGIS and python-qgis-ltr do work. Whatever I messed up! But what I actually wanted was to get PyScripter (4.1.1) working with OSGeo4W's python from your new installer and it's still complaining about the missing DLL. However, I think this is off topic?

Last edited 5 months ago by Andreas Müller (previous) (diff)

comment:6 by Andreas Müller, 5 months ago

The last try by myself was adding IDLE, which also works. I think there are two possible sources of error left: Something changed in PyScripter (filed PyScripter #1169) or in the Python install in OSGeo4W. (Third, I will eventually find a typo)

Last edited 5 months ago by jef (previous) (diff)

comment:7 by Andreas Müller, 5 months ago

I installed VSCode and used the approach provided here: https://github.com/MarByteBeep/pyqgis-standalone and described here: https://gis.stackexchange.com/questions/421362/looking-for-manual-on-how-to-properly-setup-standalone-pyqgis-without-gui

Running the example provided there (pyqgis-standalone script) is fine, using a script to import QSettings (as an example: from PyQt5.QtCore import QSettings) it fails with the same error.

[Added:] If I do from qgis.PyQt.QtCore import QSettings it works in "external" IDE's (PyScripter, VSCode)

Last edited 5 months ago by Andreas Müller (previous) (diff)

comment:8 by Andreas Müller, 3 months ago

New odd information, today I found this post https://gis.stackexchange.com/questions/431096/geopandas-error-oserror-could-not-find-or-load-spatialindex-c-64-dll-in-pycha reporting that geopandas didn't load in PyCharm. His solution was to import the processing module before importing geopandas. And what should I say: This works also when importing from QtCore! It seems that external IDE's share this "bug" and I guess they all use the python interpreter from apps\Python39 and not from bin\ like my PyScripter does.

Note: See TracTickets for help on using tickets.