20

I have Anaconda as my primary Python distro, and want to route Python related QGIS scripts through it. With Anaconda, I have Spyder, can easily install packages with pip, and can launch a iPython Notebook web-browser for both screen shares and storing code I intend to execute on my data before, during, and after manipulations in QGIS (which calls on packages such as scikit-learn).

I can not find any useful anywhere on how to link the two.

I'm using Windows 8.1, but if this can only be done in Linux, I can try to set it up on my desktop, which is running Mint 13. I just need to have a webcam and mic, found on my laptop but not desktop at the moment, for an interactive demo and interview on Tues.

  • 2
    On Windows, if you are using OSGeo4W for your installer, you need to continue using its Python installation, which is what QGIS links to to create its internal Python interpreter instance. You can use other Python distros, but you would need to compile QGIS from source yourself, which also means any dependencies, like Python C-compiled modules (QScintilla, etc.), need built against that Python installation as well. In other words, it may be difficult to build from source using OSGeo4W for dependencies, while also using a different Python than OSGeo4W's. – dakcarto Nov 10 '14 at 23:23
  • what do you mean for "how to link the two" ? interchanging data with QGIS does not require tight python integration. Would be useful having QGIS in anaconda env, but it's not simple at all setting all anaconda python dependencies inside OSGeo4W env. – Luigi Pirelli Nov 28 '15 at 8:58
  • This is a very relevant question for QGIS on Windows. The Python distribution included with OSGeo4W has many outdated modules (e.g. numpy, scipy) and there are a number of modules that require compilation and/or linking (netCDF4, rasterio) that pip cannot do - but conda can. Anaconda has recipes for building gdal and many other things, so I wonder how many QGIS dependencies cannot be provided by Anaconda? – j08lue Jun 13 '16 at 12:35
  • On Linux, making your Anaconda Python the default Python might help (export PATH="/path/to/anaconda/bin:$PATH")? Or is /usr/bin/python hardcoded in QGIS? – j08lue Jun 13 '16 at 12:37
3

On Windows, your best option is currently to use the Python distribution that can be installed through OSGeo4W and install pip through the OSGeo4W installer, too.

While pip cannot install many packages that require linkage to external libraries (e.g. netCDF or GEOS) right from the package index, a workaround is to install these unofficial pre-compiled binaries from http://www.lfd.uci.edu/~gohlke/pythonlibs/ and install them in the OSGeo4W Shell through pip install path-to-downloaded-binary.whl.

[Edit 2018] Now there is also the option to install QGIS via (Ana)conda:

conda install -c conda-forge qgis
2

This can be done with conda environments. You would create an environment with a matching python version to the one qgis installs (you need to make sure both your anaconda install and qgis are the same architecture). Then you need to add the relevant paths to your environment system path and python path. There are various paths qgis prepends to the system path on startup and you can view them all through the qgis options menu iirc. To add paths to a conda environment, look here http://conda.pydata.org/docs/using/envs.html#windows . When you activate the environment all the relevant paths will be added and you should be able to import qgis libs.

This won't let you use anaconda through qgis, but it will let you use your qgis scripts etc through anaconda

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.