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.

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)

| improve this answer | |
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!

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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