[GIS] Problem getting SAGA activated in Ubuntu QGIS 2.18.2

qgisqgis-processingsagaUbuntu

By some reason SAGA does not appear into Processing Toolbox list although I have checked it to be active. See screen capture. What could be the problem?

QGIS vesion is 2.18.2 and OS is Ubuntu 16.04 (Xenial).

problem to get SAGA to be seen in Processing Toolbox list

Best Answer

Note: On 16.04, the default Ubuntu repositories for Xenial only include QGIS 2.8 Wein. The Q version we want is QGIS 2.18 Las Palmas (the current release as of the date of this post), which includes the version of the SAGA algorithm and API that the below solution works with. To remedy this situation, add the line deb http://qgis.org/debian xenial main to your /etc/apt/sources.list file and follow instructions to add the public repository key, then sudo apt-get update to get the updated source list. Then follow the steps as below.


I tried several things before I got this to work properly. First I tried both Jesus's answer and AndreJ's answer as shown below, then added my own solution. The solution I came up with ends up being kind of hacky, but it works. Some of these steps may be superfluous:

  1. Added the line deb http://ftp.ussg.iu.edu/linux/ubuntu xenial main universe to the /etc/apt/sources.list file.
  2. Removed SAGA, QGIS and associated dependencies:

    $ sudo apt-get purge saga libsaga qgis; sudo apt-get autoremove;
    
  3. Installed proper SAGA version using:

    $ sudo apt-get update; sudo apt-get install saga=2.2.3+dfsg-1build1 libsaga=2.2.3+dfsg-1build1
    
  4. Then tell apt not to touch saga and libsaga when installing updates

    $ sudo apt-mark hold saga libsaga
    
  5. Reinstalled Q:

    $ sudo apt-get install qgis
    
  6. At this point I was still not seeing the SAGA plugin. I decided to poke around in /usr/share/qgis/python/plugins/processing/algs/saga because I was desperate. I found the following statement in /usr/share/qgis/python/plugins/processing/algs/saga/SagaAlgorithmProvider.py beginning on line 76:

    if not version.startswith('2.3.'):
    ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
                           self.tr('Problem with SAGA installation: unsupported SAGA version found.'))
    return
    

    Because the version we now have is 2.2.3, I modified line 76 to be:

    if not version.startswith('2.'):
    

    Then I restarted Q, and it works! Thank you Jesus and AndreJ for the help. Upvoted for providing a terrific lead to follow.