Unable to import OTB using Pyqgis


I’m somewhat new to OTB and am trying to utilize the OTB python package in pyqgis. I have OTB properly installed and configured in the QGIS processing toolbox. When I attempt to import the library into Pyqgis I get the following error:

I’ve also attempted to conda install OTB on wsl2 but haven’t had any luck. Can anyone assist?


Hi @bryan

I think that you have to give the correct environment to the pyqgis interpreter, usualy, to import otbApplication you have to call the otbenv.bat (which is in the otb install folder) before. This script sets the correct environment variable for the import to work. I don’t know the pyqgis interpreter, maybe in the options you can call a .bat script before or give it as input of pyqgis interpreter?

I will give it a try,

Best regards

I’ve tried running the otbenv.bat file using os and subprocess modules in the script but I’m still unable to import the module into pyqgis. I’m going to keep trying a few other things and will make sure to update the thread once I find the solution.

You can try in your pyqgis console :

os.environ["OTB_APPLICATION_PATH"] = "PathToYourOTBInstall/lib/otb/applications"
os.environ["PYTHONPATH"] = "PathToYourOTBInstall/lib/python:${PYTHONPATH}"

before calling import otbApplication
To make sure you have the correct environment variables, you have to use the ones in otbenv.bat

Let me know