[GIS] Getting QGIS to work with Python2.7 Anaconda Distribution

anacondainstallationosxpythonqgis

I use Python 2.7 from Anaconda installed in a python environment on my computer (MacOS Sierra 10.12). QGIS is installed from the KyngChaos framework, and I know that there are problems with mixing other python distributions (besides the standard mac installed one) with QGIS, but I had the Anaconda Python2.7 working with QGIS up until today when I randomly received an error that the python console could not be loaded.

I then, 1) Uninstalled QGIS 2.16. 2) Installed QGIS 2.18. 3) Added this to my path: /Users/ron/anaconda/envs/python2/bin/, which is the location of my Python distribution from Anaconda.

These are the errors I am receiving from QGIS.

I am basing my actions off of the accepted answer to Setting QGIS Python version? However I'm having trouble where the accepted answer says "you must modify the symlinks in usr/bin". I am just learning about the file system and I am not really sure how I should go about modifying the symlinks.

I do have VirtualBox with Linux on my computer, so if all else fails I could just install QGIS with Conda on Linux (as right now the Conda QGIS install is only for Linx), but I feel like that would be taking the easy way out and I want to try and figure this out first.

Best Answer

I use both Macos Kyngchaos QGIS and Anaconda Python on my Mac with success.

To do this, you must set your Anaconda Python path in your QGIS variables environment.

Go to QGIS > Preferences > System

In the environment Set PYTHONPATH as a new variable and add /Applications/anaconda2/bin as a value. Set it to overwrite. Restart QGIS, you'll see the new PYTHONPATH variable loaded in the read only section above.

In Anaconda, what I did, you can even create a QGIS specific Python environment with all the necessary libraries inside. You won't need at all to add it to your Macos system paths, unless you are needing it for other applications. But in QGIS you'll have to input /Applications/anaconda2/envs/QGIS/bin instead, as the PYTHONPATH variable.

enter image description here

Then, when you install a new QGIS extension, if a python library is missing for this extension to work properly, just add it to your QGIS Anaconda installation. You won't get any errors anymore.