Error while importing otbApplication on Windows 11

Hello all,

For a few days now, I have tried to configurate the Python interface for OTB cause I want to segment automatically images via OTB.

Here is my conda work environnement :

Windows 11
Python 3.10.16
OTB 9.1

By reading the guide, I have launched the otbenv.bat, and succesfully configurated my
PATH : C:\Users\romain\workspace\OTB\lib, C:\Users\romain\workspace\OTB\bin

PYTHONPATH : C:\Users\romain\workspace\OTB\lib\otb\python

OTB_APPLICATION_PATH : C:\Users\romain\workspace\OTB\lib\otb\applications

So for me, it should work nicely… HOWEVER, each time I try to import OtbApplication module I get this error :

I believe it is caused by a wrong path or something like that, but how come ?

I also thought that my python version could be also a source of error so I used 3.10.1 version but it doesn’t really change…

I know that it is a recurrent topic, So I read related ones but no answer was able to solve my problem or at least indicate me a glimpse of a solution. And I find the guide not that helpfull…

I found an alternative though, with Qgis and it works finely… But I still wish to know what’s going on… And it would be easier to automatize my process.

Well, if anyone knows how to solve this easily, I would be really grateful !

Thanks for your time.

Hi

Starting from Python 3.8 there is specificity when doing an import which is not installed in the PYTHONPATH, you have to call “add_dll_directory” only on Windows systems. Here is an example from our Windows CI :

import os
os.add_dll_directory(“C:\build\otb\build\bin”)
os.add_dll_directory(“C:\build\otb\build\lib”)
import otbApplication as otb

Qgis plugin does not use the Python interface of OTB, it calls the CLI directly which are .exe files

Best regards

Ah I see, I didn’t know that. It worked properly this time, thanks a lot !

Best regards