fabricebrito / conda-otb

1 stars 2 forks source link

OTB not installed but can be fixed manually #1

Open floriandeboissieu opened 3 years ago

floriandeboissieu commented 3 years ago

Thanks for this conda build of OTB7.2 + geopandas, very usefull! For me the install did not work at first (miniconda3 on Centos-7): the post-link.sh script seems to stop after linking libpython (line 7 of post-link.sh) without a warning (no clue), thus leaving the OTB-7.2.0-Linux64.run file as is in otb directory and conda-otb with the link only.

I could fix it executing the post-link.sh script manually setting environment variable PREFIX=$CONDA_PREFIX:

conda env create -n otb7.2 -f environment.yml
conda activate otb7.2
PREFIX=$CONDA_PREFIX sh ~/miniconda3/pkgs/otb-7.2.0-py37_8/info/recipe/post-link.sh
floriandeboissieu commented 3 years ago

Actually, using only otbApplication in a python script works well, but when it comes to use also gdal in the same script it crashes.

There is a conflict when importing both gdal and otbApplication:

import otbApplication
import gdal

ImportError: /lib64/libstdc++.so.6: version `CXXABI_1.3.8' not found (required by /home/xxx/miniconda3/envs/otb7.2/lib/python3.7/site-packages/osgeo/../../../libgdal.so.26)

And in the other way, i.e. importing gdal first then otbApplication leads to a segmentation fault when executing an OTB app using gdal (I suppose), like ExtractROI.

floriandeboissieu commented 3 years ago

Hi @fabricebrito, Following you're tutorial https://knowledge.terradue.com/display/ELLIP/HOWTO+-+Install+OTB+with+gdal+and+geopandas, I made several tests: gdal and geopandas needs to be imported before otbApplication As in the environment.yml gdal=2.4.1 is imposed, it limits geopandas, proj and rasterio to old versions. Thus to have the latest as possible, I tried to upgrade I found a solution:

  1. gdal=3.1.4 : OTB7.2 build is with 3.1.0, so no conflict with the conda install and gdal import previous to otbAppliation can be dropped.
  2. proj=7.1.1 (problems are rising with proj=7.2) : OTB7.2 build is with 6.2.1, it does seem to have any problem with gdal but with geopandas, therefore geopandas needs to be imported

For the record, here is a summary of the whole procedure I used on centos-7:

  1. environment.yml:
    channels:
    - terradue
    - conda-forge
    dependencies:
    - python=3.7
    - click
    - otb=7.2.0
    - gdal=3.1
    - proj=7.1
    - ipykernel
    - shapely
    - pystac
    - geopandas
    - rasterio
  2. create environment:
    conda env create -n otb7.2 -f environment.yml
    conda activate otb7.2
  3. check if otbApplication can be loaded:
    python -c 'import otbApplication' 

    If there is no error, pass to next step. If there is an error (it was my case, conda would not execute fully the recipe post-link.sh), make sure the environment is activated and run the script post-link.sh from your recipe:

    PREFIX=$CONDA_PREFIX sh ~/miniconda3/pkgs/otb-7.2.0-py37_8/info/recipe/post-link.sh
  4. at the begining of a script using both geopandas and otbApplication, import geopandas first.

For me it was working perfectly with command line calls to python scripts with otbApplication and geopandas.

pycharm IDE troubleshooting In my case I was using pycharm IDE which is unseting PYTHONPATH and OTB_APPLICATION_PATH before starting the python and adding its own PYTHONPATH. In that case, the path must be set before the import of otbApplication (I also added geopandas by the way):

import sys, os, geopandas
is_conda = os.path.exists(os.path.join(sys.prefix, 'conda-meta'))
is_otb72 = os.path.exists(os.path.join(sys.prefix, 'conda-otb'))
if is_conda and is_otb72:
    sys.path.append(os.path.join(sys.prefix, 'conda-otb/lib/python')) # could be replaced by symbolic links from conda-otb/lib/python files to lib/python3.7/
    os.environ['OTB_APPLICATION_PATH'] = os.path.join(sys.prefix, 'conda-otb/lib/otb/applications')

A last thing, there is no deactivation script for the current Trradue OTB recipe, thus the environment variables are not unset when getting out of the environment. A fix could be done including these scripts in the OTB recipe of Terradue. Of course a clean build would be the best :-).

Hope this will help.