EnMAP-Box does not start if sklearn is missing

Issue #1131 resolved
Benjamin Jakimow created an issue

EnMAP-Box cannot start if sklearn is not installed (which is likely the case if installed from QGIS Plugin Repository the first time).

The EnMAP-Box core GUI needs to be able to start even without any none-standard QGIS package installed.

Tested on QGIS Dev version

How to reproduce:

  • Start EnMAP-box in environment where sklear does not exists

File "D:\Repositories\enmap-box\site-packages\typeguard\__init__.py", line 903, in wrapper
    retval = func(*args, **kwargs)
  File "D:\Repositories\enmap-box\enmapboxprocessing\algorithm\regressionbasedunmixingalgorithm.py", line 81, in initAlgorithm
    self.addParameterRegressorCode(self.P_REGRESSOR, self._REGRESSOR)
  File "D:\Repositories\enmap-box\site-packages\typeguard\__init__.py", line 903, in wrapper
    retval = func(*args, **kwargs)
  File "D:\Repositories\enmap-box\enmapboxprocessing\enmapalgorithm.py", line 602, in addParameterRegressorCode
    from enmapboxprocessing.parameter.processingparameterestimatorcodeeditwidget import \
  File "D:\OSGeo4W\apps\qgis-dev\python\qgis\utils.py", line 888, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "D:\Repositories\enmap-box\enmapboxprocessing\parameter\processingparameterestimatorcodeeditwidget.py", line 4, in <module>
    from _classic.enmapboxgeoalgorithms.estimators.classifiers import RandomForestClassifier
  File "D:\OSGeo4W\apps\qgis-dev\python\qgis\utils.py", line 888, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "D:\Repositories\enmap-box\enmapbox\coreapps\_classic\enmapboxgeoalgorithms\estimators\classifiers\RandomForestClassifier.py", line 1, in <module>
    from sklearn.ensemble import RandomForestClassifier
  File "D:\OSGeo4W\apps\qgis-dev\python\qgis\utils.py", line 888, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
ModuleNotFoundError: No module named 'sklearn'

Comments (7)

  1. Andreas Rabe

    This will happen from time to time, and we won’t be aware of the problem, until we actually follow the create-plugin-checklist:

  2. Andreas Rabe

    For testing, it’s best to not load any apps, to avoid all the optional imports:

    >>>EnMAPBox(load_core_apps=False, load_other_apps=False)

  3. Benjamin Jakimow reporter

    This way you would have never run into this issue. At some point it’s required to test like in “real word”, meaning standard QGIS without additional packages.

  4. Andreas Rabe

    Note that if you load apps, you get all kinds of import errors from optional packages.

    So if you want to check for required imports, it’s best to deactivate apps.

    Or are you saying, that apps need to hide optional imports?

    Currently we have a lot of them:

    Traceback (most recent call last):
      File "D:\source\QGISPlugIns\enmap-box\enmapbox\gui\applications.py", line 296, in addApplicationFolder
        apps = factory(self.mEnMAPBox)
      File "D:\source\QGISPlugIns\enmap-box\enmapbox\apps\enpt_app\__init__.py", line 8, in enmapboxApplicationFactory
        from enpt_enmapboxapp.enpt_enmapboxapp import EnPTEnMAPBoxApp
      File "C:\QGIS\apps\qgis\python\qgis\utils.py", line 888, in _import
        mod = _builtin_import(name, globals, locals, fromlist, level)
      File "D:\pycharm\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
        module = self._system_import(name, *args, **kwargs)
      File "D:\source\QGISPlugIns\enmap-box\tests\non-blocking-dependencies\enpt_enmapboxapp\__init__.py", line 1, in <module>
        raise ModuleNotFoundError('enpt_enmapboxapp')
    ModuleNotFoundError: enpt_enmapboxapp
    ModuleNotFoundError:enpt_enmapboxapp
    Traceback:
      File "D:\source\QGISPlugIns\enmap-box\enmapbox\gui\applications.py", line 296, in addApplicationFolder
        apps = factory(self.mEnMAPBox)
      File "D:\source\QGISPlugIns\enmap-box\enmapbox\apps\enpt_app\__init__.py", line 8, in enmapboxApplicationFactory
        from enpt_enmapboxapp.enpt_enmapboxapp import EnPTEnMAPBoxApp
      File "C:\QGIS\apps\qgis\python\qgis\utils.py", line 888, in _import
        mod = _builtin_import(name, globals, locals, fromlist, level)
      File "D:\pycharm\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
        module = self._system_import(name, *args, **kwargs)
      File "D:\source\QGISPlugIns\enmap-box\tests\non-blocking-dependencies\enpt_enmapboxapp\__init__.py", line 1, in <module>
        raise ModuleNotFoundError('enpt_enmapboxapp')
    Traceback (most recent call last):
      File "D:\source\QGISPlugIns\enmap-box\enmapbox\gui\applications.py", line 296, in addApplicationFolder
        apps = factory(self.mEnMAPBox)
      File "D:\source\QGISPlugIns\enmap-box\enmapbox\apps\ensomap\__init__.py", line 35, in enmapboxApplicationFactory
        from ensomap.enmapboxintegration import EnSoMAP
      File "C:\QGIS\apps\qgis\python\qgis\utils.py", line 888, in _import
        mod = _builtin_import(name, globals, locals, fromlist, level)
      File "D:\pycharm\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
        module = self._system_import(name, *args, **kwargs)
      File "D:\source\QGISPlugIns\enmap-box\enmapbox\apps\ensomap\enmapboxintegration.py", line 32, in <module>
        import hys
      File "C:\QGIS\apps\qgis\python\qgis\utils.py", line 888, in _import
        mod = _builtin_import(name, globals, locals, fromlist, level)
      File "D:\pycharm\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
        module = self._system_import(name, *args, **kwargs)
      File "D:\source\QGISPlugIns\enmap-box\enmapbox\apps\ensomap\hys\__init__.py", line 26, in <module>
        from .tools import *
      File "C:\QGIS\apps\qgis\python\qgis\utils.py", line 888, in _import
        mod = _builtin_import(name, globals, locals, fromlist, level)
      File "D:\pycharm\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
        module = self._system_import(name, *args, **kwargs)
      File "D:\source\QGISPlugIns\enmap-box\enmapbox\apps\ensomap\hys\tools.py", line 5, in <module>
        from numba import jit, float32, void, intc, int64, int32
      File "C:\QGIS\apps\qgis\python\qgis\utils.py", line 888, in _import
        mod = _builtin_import(name, globals, locals, fromlist, level)
      File "D:\pycharm\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
        module = self._system_import(name, *args, **kwargs)
      File "D:\source\QGISPlugIns\enmap-box\tests\non-blocking-dependencies\numba\__init__.py", line 1, in <module>
        raise ModuleNotFoundError('numba')
    ModuleNotFoundError: numba
    ModuleNotFoundError:numba
    Traceback:
      File "D:\source\QGISPlugIns\enmap-box\enmapbox\gui\applications.py", line 296, in addApplicationFolder
        apps = factory(self.mEnMAPBox)
      File "D:\source\QGISPlugIns\enmap-box\enmapbox\apps\ensomap\__init__.py", line 35, in enmapboxApplicationFactory
        from ensomap.enmapboxintegration import EnSoMAP
      File "C:\QGIS\apps\qgis\python\qgis\utils.py", line 888, in _import
        mod = _builtin_import(name, globals, locals, fromlist, level)
      File "D:\pycharm\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
        module = self._system_import(name, *args, **kwargs)
      File "D:\source\QGISPlugIns\enmap-box\enmapbox\apps\ensomap\enmapboxintegration.py", line 32, in <module>
        import hys
      File "C:\QGIS\apps\qgis\python\qgis\utils.py", line 888, in _import
        mod = _builtin_import(name, globals, locals, fromlist, level)
      File "D:\pycharm\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
        module = self._system_import(name, *args, **kwargs)
      File "D:\source\QGISPlugIns\enmap-box\enmapbox\apps\ensomap\hys\__init__.py", line 26, in <module>
        from .tools import *
      File "C:\QGIS\apps\qgis\python\qgis\utils.py", line 888, in _import
        mod = _builtin_import(name, globals, locals, fromlist, level)
      File "D:\pycharm\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
        module = self._system_import(name, *args, **kwargs)
      File "D:\source\QGISPlugIns\enmap-box\enmapbox\apps\ensomap\hys\tools.py", line 5, in <module>
        from numba import jit, float32, void, intc, int64, int32
      File "C:\QGIS\apps\qgis\python\qgis\utils.py", line 888, in _import
        mod = _builtin_import(name, globals, locals, fromlist, level)
      File "D:\pycharm\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
        module = self._system_import(name, *args, **kwargs)
      File "D:\source\QGISPlugIns\enmap-box\tests\non-blocking-dependencies\numba\__init__.py", line 1, in <module>
        raise ModuleNotFoundError('numba')
    Load EnMAPBoxApplication(s) from "hzg_onns"
    Load EnMAPBoxApplication(s) from "lmuvegetationapps"
    Load EnMAPBoxApplication(s) from "specmixapp"
    Load EnMAPBoxApplication(s) from "spectralindexoptimizerapp"
    Messages(1): EnMAPBoxApplication error(s)
    Traceback (most recent call last):
      File "D:\source\QGISPlugIns\enmap-box\enmapbox\gui\applications.py", line 284, in addApplicationFolder
        appModule = importlib.import_module(appPkgName)
      File "C:\QGIS\apps\Python39\lib\importlib\__init__.py", line 127, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
      File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
      File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 855, in exec_module
      File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
      File "D:\source\QGISPlugIns\enmap-box\enmapbox\apps\spectralindexoptimizerapp\__init__.py", line 2, in <module>
        from spectralindexoptimizerapp.processingalgorithm import SpectralIndexOptimizerProcessingAlgorithm
      File "C:\QGIS\apps\qgis\python\qgis\utils.py", line 888, in _import
        mod = _builtin_import(name, globals, locals, fromlist, level)
      File "D:\pycharm\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
        module = self._system_import(name, *args, **kwargs)
      File "D:\source\QGISPlugIns\enmap-box\enmapbox\apps\spectralindexoptimizerapp\processingalgorithm.py", line 4, in <module>
        from spectralindexoptimizerapp.core import spectralIndexOptimizer
      File "C:\QGIS\apps\qgis\python\qgis\utils.py", line 888, in _import
        mod = _builtin_import(name, globals, locals, fromlist, level)
      File "D:\pycharm\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
        module = self._system_import(name, *args, **kwargs)
      File "D:\source\QGISPlugIns\enmap-box\enmapbox\apps\spectralindexoptimizerapp\core.py", line 5, in <module>
        from sklearn.linear_model import LinearRegression
      File "C:\QGIS\apps\qgis\python\qgis\utils.py", line 888, in _import
        mod = _builtin_import(name, globals, locals, fromlist, level)
      File "D:\pycharm\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
        module = self._system_import(name, *args, **kwargs)
      File "D:\source\QGISPlugIns\enmap-box\tests\non-blocking-dependencies\sklearn\__init__.py", line 1, in <module>
        raise ModuleNotFoundError('sklearn')
    ModuleNotFoundError: sklearn
    ModuleNotFoundError:sklearn
    Traceback:
      File "D:\source\QGISPlugIns\enmap-box\enmapbox\gui\applications.py", line 284, in addApplicationFolder
        appModule = importlib.import_module(appPkgName)
      File "C:\QGIS\apps\Python39\lib\importlib\__init__.py", line 127, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
      File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
      File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 855, in exec_module
      File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
      File "D:\source\QGISPlugIns\enmap-box\enmapbox\apps\spectralindexoptimizerapp\__init__.py", line 2, in <module>
        from spectralindexoptimizerapp.processingalgorithm import SpectralIndexOptimizerProcessingAlgorithm
      File "C:\QGIS\apps\qgis\python\qgis\utils.py", line 888, in _import
        mod = _builtin_import(name, globals, locals, fromlist, level)
      File "D:\pycharm\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
        module = self._system_import(name, *args, **kwargs)
      File "D:\source\QGISPlugIns\enmap-box\enmapbox\apps\spectralindexoptimizerapp\processingalgorithm.py", line 4, in <module>
        from spectralindexoptimizerapp.core import spectralIndexOptimizer
      File "C:\QGIS\apps\qgis\python\qgis\utils.py", line 888, in _import
        mod = _builtin_import(name, globals, locals, fromlist, level)
      File "D:\pycharm\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
        module = self._system_import(name, *args, **kwargs)
      File "D:\source\QGISPlugIns\enmap-box\enmapbox\apps\spectralindexoptimizerapp\core.py", line 5, in <module>
        from sklearn.linear_model import LinearRegression
      File "C:\QGIS\apps\qgis\python\qgis\utils.py", line 888, in _import
        mod = _builtin_import(name, globals, locals, fromlist, level)
      File "D:\pycharm\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
        module = self._system_import(name, *args, **kwargs)
      File "D:\source\QGISPlugIns\enmap-box\tests\non-blocking-dependencies\sklearn\__init__.py", line 1, in <module>
        raise ModuleNotFoundError('sklearn')
    Unable to import sklearn:
     sklearn
    Unable to import astropy:
     astropy
    Unable to import OpenGL:
     OpenGL
    Unable to import numba:
     numba
    Unable to import netCDF4:
     netCDF4
    Unable to import enpt_enmapboxapp:
     enpt_enmapboxapp
    
  5. Log in to comment