Using QGIS from Conda

QGIS recipes have been available on Conda for a while, but now, that they work for the three main operating systems, getting QGIS from Conda is s starting to become a reliable alternative to other QGIS distributions. Anyway, let’s rewind a bit…

What is Conda?

Conda is an open source package management system and environment management system that runs on Windows, macOS and Linux. Conda quickly installs, runs and updates packages and their dependencies. Conda easily creates, saves, loads and switches between environments on your local computer. It was created for Python programs, but it can package and distribute software for any language.

Why is that of any relevance?

Conda provides a similar way to build, package and install QGIS (or any other software) in Linux, Windows, and Mac.

As a user, it’s the installation part that I enjoy the most. I am a Linux user, and one of the significant limitations is not having an easy way to install more than one version of QGIS on my machine (for example the latest stable version and the Long Term Release). I was able to work around that limitation by compiling QGIS myself, but with Conda, I can install as many versions as I want in a very convenient way.

The following paragraphs explain how to install QGIS using Conda. The instructions and Conda commands should be quite similar for all the operating systems.

Anaconda or miniconda?

First thing you need to do is to install the Conda packaging system. Two distributions install Conda: Anaconda and Miniconda.

TL;DR Anaconda is big (3Gb?) and installs the packaging system and a lot of useful tools, python packages, libraries, etc… . Miniconda is much smaller and installs just the packaging system, which is the bare minimum that you need to work with Conda and will allow you to selectively install the tools and packages you need. I prefer the later.

For more information, check this stack exchange answer on anaconda vs miniconda.

Download anaconda or miniconda installers for your system and follow the instructions to install it.

Windows installer is an executable, you should run it as administrator. The OSX and Linux installers are bash scripts, which means that, once downloaded, you need to run something like this to install:

bash Miniconda3-latest-Linux-x86_64.sh

Installing QGIS

Notice that the Conda tools are used in a command line terminal. Besides, on Windows, you need to use the command prompt that is installed with miniconda.

Using environments

Conda works with environments, which are similar to Python virtual environments but not limited only to python. Basically, it allows isolating different installations or setups without interfering with the rest of the system. I recommend that you always use environments. If, like me, you want to have more that one version of QGIS installed, then the use of environments is mandatory.

Creating an environment is as easy as entering the following command on the terminal:

conda create --name <name_of_the_environment>

For example,

conda create --name qgis_stable

You can choose the version of python to use in your environment by adding the option python=<version>. Currently versions of QGIS run on python 3.6, 3.7, 3.8 and 3.9.

conda create –name qgis_stable python=3.7

To use an environment, you need to activate it.

conda activate qgis_stable

Your terminal prompt will show you the active environment.

(qgis_stable) aneto@oryx:~/miniconda3$

To deactivate the current environment, you run

conda deactivate

Installing packages

Installing packages using Conda is as simples as:

conda install <package_name>

Because conda packages can be stored in different channels, and because the default channels (from the anaconda service) do not contain QGIS, we need to specify the channel we want to get the package from. conda-forge is a community-driven repository of conda recipes and includes updated QGIS packages.

conda install qgis --channel conda-forge

Conda will download the latest available version of QGIS and all its dependencies installing it on the active environment.

Note: Because conda always try to install the latest version, if you want to use the QGIS LTR version, you must specify the QGIS version.

conda install qgis=3.10.12 --channel conda-forge

Uninstalling packages

Uninstalling QGIS is also easy. The quickest option is to delete the entire environment where QGIS was installed. Make sure you deactivate it first.

conda deactivate
conda env remove --name qgis_stable

Another option is to remove QGIS package manually. This is useful if you have other packages installed that you want to keep.

conda activate qgis_stable
conda remove qgis -c conda-forge

This only removes the QGIS package and will leave all other packages that were installed with it. Note that you need to specify the conda-forge channel. Otherwise, Conda will try to update some packages from the default channels during the removal process, and things may get messy.

Running QGIS

To run QGIS, in the terminal, activate the environment (if not activated already) and run the qgis command

conda activate qgis_stable
qgis

Updating QGIS

To update QGIS to the most recent version, you need to run the following command with the respective environment active

conda update qgis -c conda-forge

To update a patch release for the QGIS LTR version you run the install command again with the new version:

conda install qgis=3.10.13 -c conda-forge

Some notes and caveats

Please be aware that QGIS packages on Conda do not provide the same level of user experience as the official Linux, Windows, and Mac installer from the QGIS.org distribution. For example, there are no desktop icons or file association, it does not include GRASS and SAGA, etc …

On the other hand, QGIS installations on Conda it will share user configurations, installed plugins, with any other QGIS installations on your system.

25 thoughts on “Using QGIS from Conda

  1. Thanks for sharing this, Alexandre!
    In the instalation process (using miniconda) I’ve done a litle mistake, trying to exit during the process.
    The installation process hwnt fine but now my Conda seems to be installed in home/user_name/Downloads/exit/
    Do you know, how to fix this? Should I uninstall Conda to choose another place?
    Thanks in advance!
    Felipe

    Like

  2. Hi Alexandre,
    I’ve created a conda enviroment and installed python 2.7.16.
    Now I’d like to install QGis 2.18.17. Once in the environment I’ve tried:

    conda install qgis=2.18.17 –channel conda-forge

    But it hasn’t worked and I’ve got the following message:

    Collecting package metadata (repodata.json): done
    Solving environment: failed
    PackagesNotFoundError: The following packages are not available from current channels:
    – qgis=2.18.17 -> dateutil

    Could you help me how to get it fixed?
    Thank you in advance
    Tiago

    Like

  3. Fantastic! – Many thanks for putting together this guide!
    I was just struggling with this question, as the downloadable Qgis installer doesn’t like the python version my Mac runs on ( I guess some other packages has changed the python version… mea culpa for not using environments : ) .

    Anyway, a big thanks for this guide. Very timely and helpful!

    Like

  4. Hi, Alexandre. I am trying to install the !GIS2ThreeJS but I got the error:
    “`
    Missing dependencies related to PyQt5 and QtWebKit. Please install “python3-pyqt5.qtwebkit” package (Debian/Ubuntu) before using this plugin.
    “`
    How can I install those dependencies on my conda env? Thanks in advance!

    Like

    1. Currently you can’t. There’s an open ticket about that issue. Conda-forge deprecated the QtWebKit feedstock, and no one is maintaining it. There are people trying to revive it, but the current version does not have that dependency available.

      Like

  5. Hi Alexander,
    I tried to install qgis from miniconda. I followed the step specified above:
    conda create –name qgis_stable
    conda activate qgis_stable
    conda install qgis –channel conda-forge
    qgis

    I get the error in https://www.gitmemory.com/issue/conda-forge/qgis-feedstock/71/499287966
    I tried most of the advice that I found by internet but none of them solve the problem.
    I would appreciate some help with this (maybe you can tell me some python and Qgis version that work fine together in windows.

    Many thanks in advance
    Regards

    Like

  6. Hi Alexandre,
    Thanks for this nice post which could perhaps help me to install an old version of QGIS which I sadly need to use a plugin : Qgis 2.14.
    Unfortunately this version of Qgis is not available on conda-forge, and when I try to install the package locally from a downloaded file (https://qgis.org/downloads/), I get the following error : ERROR: Encountered corrupt package tarball at /home/peter/miniconda2/pkgs/qgis-2.8.3.tar.bz2. Conda has left it in place. Please report this to the maintainers of your package. For the defaults channel, please report to https://github.com/continuumio/anaconda-issues

    Would you have any advice ?

    Thanks !

    Like

    1. Hi Tim,
      If that particular version of QGIS is not available, you probably would need to skip conda installation. You can’t install the packages like that. They need to be built. And for that you would need a recipe for that version. Are you on windows. If so, you can use an old standalone installer that you can find here:

      https://qgis.org/downloads/

      Like

  7. Any thoughts on why I am getting “ModuleNotFoundError: No module named ‘qgis'” when I try `import qgis’, etc from a Jupyter Notebook from this environment?
    I have “3.7.10 | packaged by conda-forge | (default, Feb 19 2021, 15:37:01) [MSC v.1916 64 bit (AMD64)]” and forced a QGIS 3.16 install in that environment…

    • I have QGIS 3.10 and ArcGIS Pro 2.7 (and associated Python, etc) installed via the Windows 10 installer
    • I am ‘sensing’ that it is something to do with PyQt (????)
    • QGIS full software opens just fine from the specific environment, i.e., the anaconda command line using `qgis’

    Thanks in advance!

    Like

    1. I am not very familiar with jupyter notebooks, but, in the past, I have tried installing jupyter on top of my QGIS installation and I was able to import qgis without any problem. whap happens if you use the plain python console in that environment?

      Like

      1. Hi Alexandre, thanks a lot for your sharing.
        But I encounter a problem.I’m on OSX. When I finish to install like you describe.I’m not able to launch QGIS desktop application. Is that normal?
        I’m using OS Big Sur and I tried with qgis 3.10, 3.16 and 3.18

        Like

  8. You mentioned that “it does not include GRASS and SAGA”. Is there a way to install them through conda as you can when running the QGIS network installer? If not, is there a way to add those plugins afterwards? I could not find them as plugins to install.

    Like

    1. There are no installers for GRASS or SAGA on conda-forge. Nevertheless, I think you can install SAGA and GRASS as standalone applications and then configure QGIS (Settings – Options – Processing) to use them. Also, at least for me on Linux, having another installation that includes GRASS and SAGA, will just work on the one installed using conda.

      Liked by 1 person

      1. Thanks, Alexandre. I’m looking at those settings, though, and am not sure how it actually integrates with those installations. There is an “Activate” option that we already have checked, but that looks like the only relevant option. Am I missing something?

        Like

Leave a comment