0

I'm developing a standalone QGIS based Python script for loading layers from/to PostgreSQL/PostGIS database. If I check the list using code:

providers = QgsProviderRegistry.instance().providerList()

I'm getting only GDAL. I have tested with

print(QgsProviderRegistry.instance().providerMetadata('postgres'))

but it is giving None

My syste details are as follows:

OS:Windows 10 
QGIS:3.16.11

How can I include PostgreSQL extension in the qgsProviderRegistry?

2
  • Is your QGIS prefix well defined? Oct 13 at 12:06
  • What is your OS? Windows, Mac, Linux? Version of your OS? Version of QGIS? Edit your question to add them, plz.
    – ThomasG77
    Oct 13 at 21:19
1

Unable to reproduce with the following code (Python 3.16 on Linux)

import sys
from qgis.core import (QgsApplication, QgsProviderRegistry)

app = QgsApplication([], True)
# On Linux, didn't need to set it so commented
# app.setPrefixPath("C:/Program Files/QGIS Brighton/apps/qgis", True)
app.initQgis()

providers = QgsProviderRegistry.instance().providerList()
print(providers)
# above statement returns
# ['DB2', 'OAPIF', 'WFS', 'arcgisfeatureserver', 'arcgismapserver', 'delimitedtext', 'gdal', 'geonode', 'gpx', 'mdal', 'memory', 'mesh_memory', 'mssql', 'ogr', 'ows', 'postgres', 'postgresraster', 'spatialite', 'vectortile', 'virtual', 'wcs', 'wms']

It clearly seems related to your library path when loading standalone Python script.

2
  • If I ran above code I'm getting ['gdal', 'memory', 'mesh_memory', 'ogr', 'vectortile']. Oct 14 at 4:50
  • What is the ouptut of QgsProviderRegistry.instance().libraryDirectory().path() ? within QGIS Python console? What is the value within your standalone script?
    – ThomasG77
    Oct 14 at 8:43

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.