I am changing my python environment from working with ArcGis and Arcpy to working with QGIS and PyQgis. And I also want to use the machinelearning possibilities from the orfeo toolbox. In doing so I have succesfully installed QGIS 3.13 on my Win10 PC and set up Pycharm for stand-alone PyQGIS development like explained here. After that I succesfully installed the orfeo toolbox (7.1.0) and inside QGIS it works like a charm.

Following the instructions of the orfeo toolbox, I added the otbenv.bat to the .bat I created and the result is:

@echo off

call "%~dp0\o4w_env.bat"
call "%OSGEO4W_ROOT%"\apps\grass\grass78\etc\env.bat
call qt5_env.bat
call py3_env.bat
call "%OSGEO4W_ROOT%"\OTB-7.1.0-Win64\otbenv.bat

@echo off
path %OSGEO4W_ROOT%\apps\qgis\bin;%OSGEO4W_ROOT%\apps\grass\grass78\lib;%OSGEO4W_ROOT%\apps\grass\grass78\bin;%PATH%
set QGIS_PREFIX_PATH=%OSGEO4W_ROOT:\=/%/apps/qgis
rem Set VSI cache to be used as buffer, see #6448
set VSI_CACHE_SIZE=1000000
set QT_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\qgis\qtplugins;%OSGEO4W_ROOT%\apps\qt5\plugins
SET PYCHARM="C:\Program Files\JetBrains\PyCharm Community Edition 2020.1.1\bin\pycharm64.exe"
start "PyCharm aware of Quantum GIS" /B %PYCHARM% %* 

But if I try to import OTB in a stand alone scripts or aan IDE like pycharm like this:

import otbApplication as otb

the error message I receive is:

ModuleNotFoundError: No module named 'otbApplication'

The only explanation that I can think of now, is that the orfeo toolbox bindings for stand alone scripts are created for python 3.5. as is written here.

When I setup a python 3.5 environment that proves to be true. And I was able to import the module. However I could not access qgis.core from this python 3.5 environment. And since there is no (Windows) QGIS version with python 3.5, there seems no straightforward way to combine qgis and the orfeo toolbox in stand-alone development.

I hope someone has dealt with this issue before.

  • I don't have a windows PC at hand, but i would try installing qgis and otb within the same conda env with anaconda. This will give you a duplicate installation of both, but should work.
    – Javier JC
    Commented Jun 14, 2020 at 12:48
  • Thanks Javier. It lookes like a sound idea, I used Anaconda3 to setup a python 3.5 environment and installed qgis with this conda. When opened a python terminal from within anaconda I tried to import qgis, using: >>>import sys and >>> from qgis.core import QgsApplication, QgsProcessingFeedback, I recieved the well known message: ImportError: No module named 'qgis'. Also orfeo toolbox doesn't provide a windows based package within conda. Is my thinking wrong?
    – Ianuam
    Commented Jun 21, 2020 at 8:41
  • I just tryed on linux to install qgis and otb with conda, and it seems dependencyes are broken too (if they weren't you could use the windows subsystem for linux). I suggest anyway that you download the otb package from conda forge, uncompress that, look at the contents of etc/conda/activate.d/otb-activate.sh, and try to figure where are those paths on windows, and how to add them to your pythonpath.
    – Javier JC
    Commented Jun 22, 2020 at 6:02


Your Answer

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