[QGIS-Developer] Best way to import gdal, ogr, osr ?

Even Rouault even.rouault at spatialys.com
Mon Oct 17 02:51:13 PDT 2022


You can just use

from osgeo import ogr
from osgeo import gdal
from osgeo import osr

That will work with any GDAL version of the last 15 years or so.

Le 17/10/2022 à 10:52, Raymond Nijssen via QGIS-Developer a écrit :
> Dear developers,
>
> What is the best way to import ogr, gdal and osr in my pyqgis script?
>
>
> This used to work in older QGIS versions:
>
> import gdal
> import ogr
> import osr
>
>
>
> Now I've changed that to:
>
> try:
>     import ogr
>     import gdal
>     import osr
> except ModuleNotFoundError:
>     from osgeo import ogr
>     from osgeo import gdal
>     from osgeo import osr
>
>
> But it's still unclear to me what would be the way to make sure my 
> script will run in anyone else's installation (Different OS and QGIS 
> version).
>
>
> Maybe there's something like this:
>
> from qgis import ogr
>
> ???
>
>
> Kind regards,
> Raymond
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

-- 
http://www.spatialys.com
My software is free, but my time generally not.



More information about the QGIS-Developer mailing list