[gdal-dev] "New" style import

Daniel Evans Daniel.Evans at jbarisk.com
Wed Apr 7 04:20:35 PDT 2021


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: Daniel.Evans at jbarisk.com
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 <gdal-dev-bounces at lists.osgeo.org> On Behalf Of Jose Gomez-Dans
Sent: 07 April 2021 12:11
To: gdal-dev <gdal-dev at lists.osgeo.org>
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20210407/71470cbb/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image609265.png
Type: image/png
Size: 9886 bytes
Desc: image609265.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20210407/71470cbb/attachment-0005.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image464149.png
Type: image/png
Size: 651 bytes
Desc: image464149.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20210407/71470cbb/attachment-0006.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image605237.png
Type: image/png
Size: 715 bytes
Desc: image605237.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20210407/71470cbb/attachment-0007.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image663108.png
Type: image/png
Size: 966 bytes
Desc: image663108.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20210407/71470cbb/attachment-0008.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image903814.png
Type: image/png
Size: 784 bytes
Desc: image903814.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20210407/71470cbb/attachment-0009.png>


More information about the gdal-dev mailing list