qgis / QGIS-Mac-Packager

Scripts for Official QGIS MacOS Packages
https://www.qgis.org
GNU General Public License v2.0
54 stars 21 forks source link

unable to import gdal (deprecated) #114

Closed PeterPetrik closed 3 years ago

PeterPetrik commented 3 years ago
import gdal
Traceback (most recent call last):
  File "/Applications/QGIS-Dev.app/Contents/MacOS/../Resources/python/code.py", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
  File "/Applications/QGIS-Dev.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 798, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
ModuleNotFoundError: No module named 'gdal'

but import osgeo works

(nightly from 12/02/2021: QGIS version | 3.17.0-Master | QGIS code revision | 4137287031 )

PeterPetrik commented 3 years ago

import osgeo.gdal works too

PeterPetrik commented 3 years ago

looks like import gdal is deprecated and removed from GDAL 3.2.1 version we use, see https://pypi.org/project/GDAL/ section "Usage"

PeterPetrik commented 3 years ago

this is problem with the QGIS plugins that use import gdal, they should update to

try:
    from osgeo import gdal
except ImportError:
    import gdal

as suggested in the docs

PeterPetrik commented 3 years ago

created ticket for pdaltools https://gitlab.com/cartolab/pdaltools/-/issues/3

PeterPetrik commented 3 years ago

note that this is coming in new OSGeo4W (Windows) too!

gioman commented 3 years ago

note that this is coming in new OSGeo4W (Windows) too!

someone already found that @jonnyforestGIS @PedroVenancio

PeterPetrik commented 3 years ago

fixes OS Translator II: https://github.com/lutraconsulting/ostranslator-ii/commit/62d262901675185d43655b41942ed837e7ae37b3