0

I am trying to create a standalone script with QGIS functionality however I continuously run into this error regarding QT platform plugin not loading "windows" not loading.

Current error code:

qt.qpa.plugin: Could not load the Qt platform plugin "windows" in "C:\OSGEO4~1\apps\Qt5\plugins" even though it was found. This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem. Available platform plugins are: direct2d, minimal, offscreen, windows.

I set the QT_DEBUG_PLUGINS environment variable in attempt to confirm that QT was looking in the right folders to look for this plugin and I got this

QFactoryLoader::QFactoryLoader() checking directory path "C:/OSGEO4~1/apps/Qt5/plugins" ...
QFactoryLoader::QFactoryLoader() checking directory path "C:/OSGeo4W64/apps/Python37" ...
QFactoryLoader::QFactoryLoader() looking at "C:/OSGeo4W64/apps/Python37/python3.dll"
"Failed to extract plugin meta data from 'C:/OSGeo4W64/apps/Python37/python3.dll'" 
         not a plugin
QFactoryLoader::QFactoryLoader() looking at "C:/OSGeo4W64/apps/Python37/python37.dll"
"Failed to extract plugin meta data from 'C:/OSGeo4W64/apps/Python37/python37.dll'" 
         not a plugin
QFactoryLoader::QFactoryLoader() checking directory path "C:/OSGEO4~1/apps/Qt5/plugins/platforms" ...
QFactoryLoader::QFactoryLoader() looking at "C:/OSGEO4~1/apps/Qt5/plugins/platforms/qdirect2d.dll"
Found metadata in lib C:/OSGEO4~1/apps/Qt5/plugins/platforms/qdirect2d.dll, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "direct2d"
        ]
    },
    "className": "QWindowsDirect2DIntegrationPlugin",
    "debug": false,
    "version": 330498
}


Got keys from plugin meta data ("direct2d")
QFactoryLoader::QFactoryLoader() looking at "C:/OSGEO4~1/apps/Qt5/plugins/platforms/qdirect2dd.dll"
Found metadata in lib C:/OSGEO4~1/apps/Qt5/plugins/platforms/qdirect2dd.dll, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "direct2d"
        ]
    },
    "className": "QWindowsDirect2DIntegrationPlugin",
    "debug": true,
    "version": 330498
}


"The plugin 'C:/OSGEO4~1/apps/Qt5/plugins/platforms/qdirect2dd.dll' uses incompatible Qt library. (Cannot mix debug and release libraries.)" 
         not a plugin
QFactoryLoader::QFactoryLoader() looking at "C:/OSGEO4~1/apps/Qt5/plugins/platforms/qminimal.dll"
Found metadata in lib C:/OSGEO4~1/apps/Qt5/plugins/platforms/qminimal.dll, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "minimal"
        ]
    },
    "className": "QMinimalIntegrationPlugin",
    "debug": false,
    "version": 330498
}


Got keys from plugin meta data ("minimal")
QFactoryLoader::QFactoryLoader() looking at "C:/OSGEO4~1/apps/Qt5/plugins/platforms/qminimald.dll"
Found metadata in lib C:/OSGEO4~1/apps/Qt5/plugins/platforms/qminimald.dll, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "minimal"
        ]
    },
    "className": "QMinimalIntegrationPlugin",
    "debug": true,
    "version": 330498
}


"The plugin 'C:/OSGEO4~1/apps/Qt5/plugins/platforms/qminimald.dll' uses incompatible Qt library. (Cannot mix debug and release libraries.)" 
         not a plugin
QFactoryLoader::QFactoryLoader() looking at "C:/OSGEO4~1/apps/Qt5/plugins/platforms/qoffscreen.dll"
Found metadata in lib C:/OSGEO4~1/apps/Qt5/plugins/platforms/qoffscreen.dll, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "offscreen"
        ]
    },
    "className": "QOffscreenIntegrationPlugin",
    "debug": false,
    "version": 330498
}


Got keys from plugin meta data ("offscreen")
QFactoryLoader::QFactoryLoader() looking at "C:/OSGEO4~1/apps/Qt5/plugins/platforms/qoffscreend.dll"
Found metadata in lib C:/OSGEO4~1/apps/Qt5/plugins/platforms/qoffscreend.dll, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "offscreen"
        ]
    },
    "className": "QOffscreenIntegrationPlugin",
    "debug": true,
    "version": 330498
}


"The plugin 'C:/OSGEO4~1/apps/Qt5/plugins/platforms/qoffscreend.dll' uses incompatible Qt library. (Cannot mix debug and release libraries.)" 
         not a plugin
QFactoryLoader::QFactoryLoader() looking at "C:/OSGEO4~1/apps/Qt5/plugins/platforms/qwindows.dll"
Found metadata in lib C:/OSGEO4~1/apps/Qt5/plugins/platforms/qwindows.dll, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "windows"
        ]
    },
    "className": "QWindowsIntegrationPlugin",
    "debug": false,
    "version": 330498
}


Got keys from plugin meta data ("windows")
QFactoryLoader::QFactoryLoader() looking at "C:/OSGEO4~1/apps/Qt5/plugins/platforms/qwindowsd.dll"
Found metadata in lib C:/OSGEO4~1/apps/Qt5/plugins/platforms/qwindowsd.dll, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "windows"
        ]
    },
    "className": "QWindowsIntegrationPlugin",
    "debug": true,
    "version": 330498
}


"The plugin 'C:/OSGEO4~1/apps/Qt5/plugins/platforms/qwindowsd.dll' uses incompatible Qt library. (Cannot mix debug and release libraries.)" 
         not a plugin
QFactoryLoader::QFactoryLoader() checking directory path "C:/OSGeo4W64/apps/Python37/platforms" ...
Cannot load library C:\OSGEO4~1\apps\Qt5\plugins\platforms\qwindows.dll: The specified procedure could not be found.
QLibraryPrivate::loadPlugin failed on "C:/OSGEO4~1/apps/Qt5/plugins/platforms/qwindows.dll" : "Cannot load library C:\\OSGEO4~1\\apps\\Qt5\\plugins\\platforms\\qwindows.dll: The specified procedure could not be found."
qt.qpa.plugin: Could not load the Qt platform plugin "windows" in "C:\OSGEO4~1\apps\Qt5\plugins" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: direct2d, minimal, offscreen, windows.

The thing I noticed was while the metadata shows that qwindows, qdirect2d, qminimal and qoffscreen all have debug set to false, the metadata for qwindowsd, qdirect2dd, qminimald and qoffscreend all have this debug setting set to true. Would that be causing the

"The plugin 'C:/OSGEO4~1/apps/Qt5/plugins/platforms/qwindowsd.dll' uses incompatible Qt library. (Cannot mix debug and release libraries.)"

result after each dll?

For reference the script I was using to access QGIS using Python is the following

import os
import sys

os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = r'C:\OSGEO4~1\apps\Qt5\plugins'
os.environ['QT_DEBUG_PLUGINS'] = '1'
os.environ['PATH'] += r'C:\OSGEO4~1\apps\Qt5\bin; C:\OSGeo4W64\apps\qgis\bin'
sys.path.extend([r'C:\OSGeo4W64\apps\qgis\python', r'C:\OSGeo4W64\apps\Python37\lib\site-packages'])

from qgis.core import *
from PyQt5 import *


QgsApplication.setPrefixPath(r'C:\OSGEO4~1\apps\qgis', True)

qgs = QgsApplication([], False)

qgs.initQgis()

QGIS_project = QgsProject.instance()
print(QGIS_project)
QGIS_project.read('PATH TO QGIS PROJECT')

print(QGIS_project)
map_layers = QGIS_project.mapLayers()
print(map_layers)
raster_layer = QGIS_project.mapLayersByName('raster_test')
shapefile_layer = QGIS_project.mapLayersByName('shapefile_test')

print(raster_layer)
print(shapefile_layer)

1 Answer 1

1

I figured out the problem. Remove the debug dlls from the platforms folder if you have any to prevent the issue of mixing debug and release builds.

So I only have the following in the platforms folder

  • qdirect2d.dll
  • qminimal.dll
  • qoffscreen.dll
  • qwindows.dll

and put the other dlls in a separate folder called DEBUG

I also modified the windows batch file to include a call to the qt5_env.bat

@echo off
set OSGEO4W_ROOT=C:\OSGeo4W64
call %OSGEO4W_ROOT%\bin\o4w_env.bat
call %OSGEO4W_ROOT%\apps\grass\grass78\etc\qt5_env.bat <---- added this to the batch file

REM PATH setup
path %PATH%;%OSGEO4W_ROOT%\apps\qgis\bin
path %PATH%;%OSGEO4W_ROOT%\apps\Python37\Scripts
path %PATH%;%OSGEO4W_ROOT%\apps\Qt5\bin

REM QGIS setup
set QGIS_PREFIX_PATH=%OSGEO4W_ROOT%\apps\qgis
set QT_QPA_PLATFORM_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\Qt5\plugins\platforms
set PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\qgis\python

REM GRASS setup
set GRASSBIN=%OSGEO4W_ROOT%\bin\grass78.bat
set PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\grass\grass78\etc\python

Running this new python script

import os
import sys

# ADD THIS PRIOR TO CALLING qgis.core

os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = 'C:\\OSGeo4W64\\apps\\Qt5\\plugins'
os.environ['PATH'] += ';C:\\OSGeo4W64\\apps\\qgis\\bin;C:\\OSGeo4W64\\apps\\Qt5\\bin'
sys.path.extend(['C:\\OSGeo4W64\\apps\\qgis\\python', 'C:\\OSGeo4W64\\apps\\Python37\\lib\\site-packages'])

from qgis.core import *

QgsApplication.setPrefixPath('C:\\OSGeo4W64\\apps\\qgis', True)


qgs = QgsApplication([], True)

qgs.initQgis()

# This is where you would do things

qgs.exitQgis()

And it worked without errors.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.