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)