Error when importing otbApplication to QGIS Python Console

Hi all,

I’m new to Orfeo and have the following problem:
When calling

import otbApplication

in the QGIS Python Console, I get this error message:

Traceback (most recent call last):
File “C:\Program Files\OTB\lib\python\otbApplication.py”, line 14, in swig_import_helper
return importlib.import_module(mname)
File “C:\PROGRA~1\QGIS3~1.4\apps\Python37\lib\importlib_init_.py”, line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 1006, in _gcd_import
File “”, line 983, in _find_and_load
File “”, line 967, in _find_and_load_unlocked
File “”, line 670, in _load_unlocked
File “”, line 583, in module_from_spec
File “”, line 1043, in create_module
File “”, 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:\PROGRA~1\QGIS3~1.4\apps\Python37\lib\code.py”, line 90, in runcode
exec(code, self.locals)
File “”, line 1, in
File “C:/PROGRA~1/QGIS3~1.4/apps/qgis-ltr/./python\qgis\utils.py”, line 672, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
File “C:\Program Files\OTB\lib\python\otbApplication.py”, line 17, in
_otbApplication = swig_import_helper()
File “C:\Program Files\OTB\lib\python\otbApplication.py”, line 16, in swig_import_helper
return importlib.import_module('otbApplication’)
File "C:\PROGRA~1\QGIS3~1.4\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.

Apparently other people could solve this problem by creating PYTHONPATH and PATH environment variables. I did that, and it didn’t help.

Any ideas what else I could try?

Oh, and I’m using Windows 10, QGIS 3.4.7, OTB 6.6.1.

Hello,

What is the value of your PYTHONPATH ? It seems that you are using python3, so the PYTHONPATH should be PYTHONPATH=${PYTHONPATH}:path/to/otb/lib/python3, is it the case ?

You should also set the OTB_APPLICATION_PATH to path/to/otb/lib/otb/applications. I don’t think this is the cause of your problem but if this variable is not set there you won’t be able to create otb applications.

Is there any reason for you to use the python console of QGIS instead of the qgis otb plugin ?

Cédric