2

I would like to use the orfeo-toolbox via the QGIS Python Console, however, I don't seem to be able to import the otbApplication. I keep getting the following error:

import otbApplication
Traceback (most recent call last):
  File "C:\OTB\lib\python3\otbApplication.py", line 14, in swig_import_helper
    return importlib.import_module(mname)
  File "C:\OSGEO4~1\apps\Python37\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 670, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 583, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 1043, in create_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\OSGEO4~1\apps\Python37\lib\code.py", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
  File "C:/OSGEO4~1/apps/qgis/./python\qgis\utils.py", line 737, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "C:\OTB\lib\python3\otbApplication.py", line 17, in <module>
    _otbApplication = swig_import_helper()
  File "C:\OTB\lib\python3\otbApplication.py", line 16, in swig_import_helper
    return importlib.import_module('_otbApplication')
  File "C:\OSGEO4~1\apps\Python37\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: DLL load failed: The specified module could not be found.

I am using a Windows 10 computer and QGIS 3.8.2. I downloaded OTB 6.6.1, cloned the qgis-otb-plugin, and configured the environment variables as described in the Orfeo Toolbox Cookbook and various other resources.

I can use the OTB tools in the QGIS GUI, but not import it into the QGIS Python Console.

  • You can try import like this: gis.stackexchange.com/questions/220427/… – Jhon Galindo Aug 24 at 13:53
  • @Jhon Galindo: Thanks, tried that, and the import command itself did not give me an error back, but when I tried to actually run one of the otb toos (I tried Segmentation), I got "NameError: name 'otbApplication' is not defined" back, so I don't think this is the solution to the problem. – mnowatzki Aug 24 at 14:25
1

OTB python bindings are prebuilt for a specific version of python3 which I think is bit older than python3.x used in OSGeo4W

Possible workarounds: (order of increasing difficulty)

  • Check if OSGeo4W can use same python version OTB uses in its built. If so, reinstall qgis with that python version.

  • Install python version used by OTB and call "import otbApplication" in that python's console. (python is fairly easy to install on windows)

  • Rebuild only python bindings using OTB windows package using OSGeo4W python libs (requires compiler, swig etc...)

  • Raise issue on gitlab and if otb team make a priority issue, then you can wait for MR and grab the next days binary package (no wait for release)

  • Wait for otb to find and make this issue priority themselves . (less likely to happen)

OTB works in QGIS GUI is not a surprise because I specifically taken care to not use python bindings of OTB in OTB QGIS Provider.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.