In 3.1 and earlier, GDAL had short helper scripts to allow the deprecated 
imports, named “gdal.py”, “osr.py”, and “ogr.py”, with contents like:

```
# import osgeo.gdal as a convenience
from osgeo.gdal import deprecation_warn
deprecation_warn('gdal')

from osgeo.gdal import *
```

You could create such very short modules on your local machine (presumably not 
bothering to include the deprecation warning!). Using PYTHONPATH to point to a 
directory with them in is probably the simplest way.

The source for the Python wrappers in GDAL 3.1 can be found at: 
https://github.com/OSGeo/gdal/tree/release/3.1/gdal/swig/python

(Alternatively, I’d argue it wouldn’t be too hard to do some global search and 
replace for “import gdal”->”from osgeo import gdal”, using your IDE or some 
command line tools, but I presume you’re not tempted by that idea!)

Dr Daniel Evans
Software Developer


e: [email protected]
t: +44 (0)1756 799919
www.jbarisk.com
All JBA Risk Management's email messages contain confidential information and 
are intended only for the individual(s) named. If you are not the named 
addressee you should not disseminate, distribute or copy this e-mail.
Please notify the sender immediately by email if you have received this email 
by mistake and delete this email from your system.
JBA Risk Management Limited is registered in England, company number 07732946, 
1 Broughton Park, Old Lane North, Broughton, Skipton, North Yorkshire, BD23 
3FD, England.
From: gdal-dev <[email protected]> On Behalf Of Jose Gomez-Dans
Sent: 07 April 2021 12:11
To: gdal-dev <[email protected]>
Subject: [gdal-dev] "New" style import

Hi,
I've recently updated GDAL to 3.2.1. I mostly use it from Python, and have 
oodles of scripts from the past that use "import gdal" somewhere. With the 
newer versions of GDAL, this is deprecated and is now "from osgeo import gdal".

Is there some hacky workaround/sacrifice to the technical debt gods to carry on 
using "import gdal" for legacy codes?

Thanks!
Jose
_______________________________________________
gdal-dev mailing list
[email protected]
https://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to