Python import otbApplication and gdal

Hi all,

I have some python scripts that i use for othorectification process. Theses scripts use gdal and otbApplication, but i don’t succeed to import gdal if i use the otbenv.bat file.
I already downloaded and installed gdal library from the OSGeo installer but i don’t kow how i can set correctly my environnements variables.
My systeme is windows 10.
If anybody can give me some ideas it would be great.
Thank you for your time.

Hello,

Maybe you are experiencing this bug.

What is the order of your imports ?

The following should work :

#!/usr/bin/env python3

import otbApplication as otb
import gdal

while the code belove might crash …

#!/usr/bin/env python3
import gdal
import otbApplication as otb

Cédric

Hi,

Thank you for your reply.
I had noticed this bug but i think my problem is more basic than this.

In fact, until now, i used the previous verion of otb (6.6.1) with python 2.7 and i created a tricky bat file that allowed me to set my environements variables (PATH and PYTHONPATH). But now i would liked to use the newest version of OTB who works only with python 3.5 (if i read correctly the Cookbook documentation). But this time i don’t get how to set my variables in the right way.
From the osgeo console i can import gdal in python and from otb console i can import otbApplication. But i can’t import both on the same console…

I don’t know how to install and set correctly otb 7.1.0 with gdal for a python usage.

Again, thank you for your time.

Hello again,

After many tries and many reads about this issues i still can’t import otbApplication in python.
I think i set correctly my environnement variables (see bellow). I use python 3.5.4. At this point i can import gdal but otbApplication give me a dll load failed message.

The error message:

My environnements variables:
PATH
image

PYTHONPATH
image

I also set the OTB_APPLICATION_PATH to the right directory : C:\OTB-7.1.0-Win64\lib\otb\applications

If anyone has an idea ?
Many thanks in advance

Stich.

Hi Stich,

OTB uses his own GDAL binaries and libs. I believe your error is normal, you can’t import two different instances of GDAL. So if you need OTB, you should use the GDAL from your OTB installation. To do so, you need your OTB path to be first in PATH and PYTHONPATH (at least before your own GDAL installation).

Hope this will help