Skip to content

Instantly share code, notes, and snippets.

@AsgerPetersen
Last active November 5, 2021 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AsgerPetersen/c101ab4a6bcb463f1c3941c058e58fc4 to your computer and use it in GitHub Desktop.
Save AsgerPetersen/c101ab4a6bcb463f1c3941c058e58fc4 to your computer and use it in GitHub Desktop.
QGIS using conda on OSX

QGIS on OSX with Conda

Install Anaconda or Miniconda from here https://docs.conda.io/projects/conda/en/latest/user-guide/install/macos.html

Create a conda environment in which you will install QGIS. In this example we call it conda_qgis.

> conda create -n conda_qgis
> conda activate conda_qgis

Install QGIS into the environment:

> conda install qgis

This will install the latest available version of QGIS. If you need a specific version, you can see the available versions by executing conda search qgis.

Now you should be able to just run

> qgis

But because of this issue QGIS may not show its GUI.

If QGIS doesn´t open, you can fix it by adding an environment variable. But you don´t want to manually add it every time you start QGIS. Do this instead:

First figure out where the files for your environment conda_qgis is located. Run

> conda info

and look for active env location in the output. In my case the path is /Users/asger/opt/miniconda3/envs/conda_qgis.

Now open the file [YourCondaEnv]/etc/conda/activate.d/qgis-activate.sh and add this line at the end of the file

export QT_MAC_WANTS_LAYER=1

To be nice we also open this file [YourCondaEnv]/etc/conda/deactivate.d/qgis-deactivate.sh and add this line at the end

unset QT_MAC_WANTS_LAYER

From now on you should be able to open QGIS with a working GUI by executing

> conda activate conda_qgis
> qgis

Installing python modules

One of the cool things about having a conda based QGIS is that it uses the conda python interpreter. That means that you can just install python modules in your qgis conda environment and they will be available to you in QGIS python.

For example the current QGIS from conda complains that lxml is not available. This is easily fixed by

> conda activate conda_qgis
> conda install lxml

Which will install lxml in the environment and it will then be available for QGIS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment