JorgeGIlG / MTF_Estimator

Robust ESF, PSF, FWHM & MTF estimation from low quality images.
GNU General Public License v3.0
54 stars 8 forks source link

No module named `gdal` #11

Closed ilykos closed 3 years ago

ilykos commented 3 years ago

When I trying to import MTF Estimator in a fresh installation of QGIS 3.22.1 the plugin manager complains about:

Couldn't load plugin 'mtf_estimator' due to an error when calling its classFactory() method 

ModuleNotFoundError: No module named 'gdal' 
Traceback (most recent call last):
  File "C:\PROGRA~1/QGIS32~1.1/apps/qgis/./python\qgis\utils.py", line 423, in _startPlugin
    plugins[packageName] = package.classFactory(iface)
  File "C:\Users/Imisystem/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\mtf_estimator\__init__.py", line 35, in classFactory
    from .mtf_estimator import MtfEstimator
  File "C:\PROGRA~1/QGIS32~1.1/apps/qgis/./python\qgis\utils.py", line 888, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "C:\Users/Imisystem/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\mtf_estimator\mtf_estimator.py", line 28, in 
    from .mtf_estimator_algorithm import Mtf, Transect, sigmoid
  File "C:\PROGRA~1/QGIS32~1.1/apps/qgis/./python\qgis\utils.py", line 888, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "C:\Users/Imisystem/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\mtf_estimator\mtf_estimator_algorithm.py", line 22, in 
    import gdal
  File "C:\PROGRA~1/QGIS32~1.1/apps/qgis/./python\qgis\utils.py", line 888, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
ModuleNotFoundError: No module named 'gdal'

I've replaced import gdal with

try:
    from osgeo import gdal
except ImportError:
    import gdal

in mtf_estimator_algorithm.py

and also the standard import of osr, ogr and gdal in mtf_estimator.py with:

try:
    from osgeo import gdal
except ImportError:
    import gdal

try:
    from osgeo import ogr
except ImportError:
    import ogr

try:
    from osgeo import osr
except ImportError:
    import osr

And it seems to work now.

Please, consider making this a permanent change.

JorgeGIlG commented 3 years ago

Fixed. Thank you very much for reporting. I've already submitted the updated plugin for approval. It will be available soon.

Feedback about the plugin and/or algorithm will be highly appreciated.