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

Raymond Nijssen r.nijssen at terglobo.nl
Mon Oct 17 03:36:32 PDT 2022


Thank you Even. And that will always be available in QGIS? Without any 
extra (gdal) installations?

Let's say, I'm buying a brand new Windows laptop and install QGIS with 
the standalone installer, I can type

from osgeo import ogr

in the python console and it will just work?

Sorry, this is a bit hard to verify as I'm not wanting to buy a new 
Windows laptop :)


On 17-10-2022 11:51, Even Rouault wrote:
> 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
> 


More information about the QGIS-Developer mailing list