2

I installed both otb-bin and otb-python using OSGeo4W.

In OSGeo4W Shell, I have no problem importing otbApplication.

But I have a problem doing this in Python Shell. The error message is as below:

>>> import otbApplication
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import otbApplication
ImportError: No module named otbApplication

I guess I have to configure some environmental variables, but I have no idea.

My OS is Windows 7 and the Python version is 2.7.

0

3 Answers 3

2

As commented by @gene you appear to be getting this error:

Because otbApplicationis not in the PYTHONPATH of QGIS (you can use import processing.algs.otb)

1

I had the same problem, but in my case was using as Python API (modules). So, I think the solution also applies to QGIS environment!

I'm currently using Linux, Ubuntu 19.10, eoan!

After extract and run OTB (I just did in /opt/):

chmod +x OTB-7.0.0-Linux64.run
./OTB-7.0.0-Linux64.run

at this point you do not have all the environment variables settled, only the file that does the job (e.g. ..OTB-7.0.0-Linux64/otbenv.profile). So, in order to import otbApplication under your Python application, you have to activate all the variable specified in otbenv.profile. First, check if all dependencies are ok:

sudo apt-get install libx11-6 libxext6 libxau6 libxxf86vm1 libxdmcp6 libdrm2

activate the variables setting otbenv.profile in your ~/.profile. So, open ~/.profile and add . /opt/OTB-7.0.0-Linux64/otbenv.profile. Save and close. Finally, source ~/.profile.

If you still under virtualenv, just deactivate and activate again. To check if you properly import the environment variables, check the path printing $PYTHONPATH.

Last thing! If you run your code right now, you pretty much will get this message:

ImportError: libpython3.5m.so.rh-python35-1.0: cannot open shared object file: No such file or directory

which is suggested to create a symlink of your python binding. So, first, find its location with:

find /usr/lib -iname *libpython3.*

copy the path outputs (something like /usr/lib/x86_64-linux-gnu/libpython3.7m.so -- in my case, using Python 3.7), and execute:

ln -s /usr/lib/x86_64-linux-gnu/libpython3.7m.so /usr/lib/libpython3.5m.so.rh-python35-1.0

Now, I think you are OK to use library!

0

I am Ubuntu 20.04 user, I had the same issue.

Refer to Recompiling python binding section in orfeo documentation

  • I have python 3.8 and OTB-7.4.0, so I had to recompile python binding and swig.
  • As mentioned in Doc: If you are using another version of Python 3 than 3.5, but still want to use OTB Python bindings..
source otbenv.profile
ctest -S share/otb/swig/build_wrapping.cmake -VV
  • During testing, make sure echo $PYTHONPATH points to correct path of <OTB-App-folder>/lib/python
  • Now run python3 and try import otbApplication

Hope this helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.