Skip to content

Tips and Tutorials \ Install OTB on TREX with stand-alone packages

Install OTB on TREX with stand-alone packages

This tip will show you how to easily install OTB from binary packages on TREX.


Tools:
Difficulty:
Type: Tip


Overview

Install OTB from binary packages is very easy : we only need to unzip archive and edit a LUA file, in order to be able to load it on TREX with module load otb/9.0.0-python3.8.

Usage example

module load otb-python/3.8.13 # Python 3.8 interpreter
cd /work/softs/rh8/projets/otb
curl https://www.orfeo-toolbox.org/packages/OTB-9.0.0-Linux_RedHat.tar.gz -o OTB-9.0.0.tar.gz
tar xf OTB-9.0.0.tar.gz --one-top-level="9.0.0-python3.8-20240124-102500"
ln -s 9.0.0-python3.8-20240124-102500 9.0.0-python3.8
chmod -R a+Xr 9.0.0-python3.8-20240124-102500 # rx rights for all users
cd 9.0.0-python3.8
source otbenv.profile # Post-install setup
cd /work/softs/projets/modulefiles/otb
[ .. edit module file 9.0.0-python3.8.lua ]
[ .. edit gdal*py files in order to use Python interpreter ]
chmod 744 9.0.0-python3.8.lua

Edit Module Files

Edit a .lua file to adapt OTB path to /work/softs/projets/otb/version

In order to be able to load and use GDAL, we must set OTB_APPLICATION_PATH and PYTHONPATH :

prepend_path("OTB_APPLICATION_PATH",pathJoin(home,"lib/otb/applications"))
prepend_path("PYTHONPATH",pathJoin(home,"lib/otb/python"))
-- Permte d'accéder au GDAL de l'OTB
prepend_path("PYTHONPATH",pathJoin(home,"lib/python3.8/site-packages"))
Don't forget to add a dependency to a valid Python interpreter
-- Dependances
depend("otb-python/3.8.13")

Adapt GDAL Python script to use right Python interpreter

GDAL python scripts (like gdal_polygonize.py) use /usr/bin/python3.8 interpreter but Python is not installed there on TREX.

So we have to edit GDAL scripts to point out the right Python intrepreter (the one loaded with Python module) :

which python # in our case, Python is here : /work/softs/projets/otb-depends/python/linux-rhel8-x86_64/gcc-8.5.0/python-3.8.13-hlcco32zxfn33xnqhvadxgdqxg3jdv3j/bin/python
# Edit with sed : 
cd /work/softs/rh8/projets/otb/9.0.0-python3.8/bin
for fic in `ls gdal*py`; do
sed -i "s/\/usr\/bin\/python3.8/\/work\/softs\/projets\/otb-depends\/python\/linux-rhel8-x86_64\/gcc-8.5.0\/python-3.8.13-hlcco32zxfn33xnqhvadxgdqxg3jdv3j\/bin\/python/g" $fic;
done

Test your module

Now your module should be ready to use.

Once your tests are ok, do not forget to check UNIX ACL in order other users can load your module

Open a new session and try the following commands :

-> ml otb/9.0.0-python3.8
unload otb-python/3.8.13  : OK
unload otb/9.0.0-python3.8  : OK
load otb-python/3.8.13  : OK
load otb/9.0.0-python3.8  : OK
-> python --version
Python 3.8.13
-> otbcli_Superimpose
**** OTB environment setup complete ****
ERROR: Waiting for at least one parameter.

This is the Superimpose application, version 9.0.0
[....]
Python 3.8.13 (default, Dec  7 2023, 16:25:03)
[GCC 8.5.0 20210514 (Red Hat 8.5.0-10)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import otbApplication as otb
>>> appROI = otb.Registry.CreateApplication("ExtractROI")
>>> appROI.GetDescription()
'Extract a ROI defined by the user.'
>>> from osgeo import gdal
>>> gdal.__version__
'3.8.3'
>>> exit()
-> which gdalinfo
/work/softs/rh8/projets/otb/9.0.0-python3.8/bin/gdalinfo
-> gdal_polygonize.py
usage: gdal_polygonize.py [--help] [--help-general] [-q] [-8] [-o name=value] [-mask filename] [-nomask]
                          [-b band] [-of ogr_format] [-lco name=value] [-overwrite]
                          src_filename dst_filename [dst_layername] [dst_fieldname]
gdal_polygonize.py: error: the following arguments are required: src_filename, dst_filename

Contacts

    Questions ? Get help on the Forum