Skip to content

Instantly share code, notes, and snippets.

@AsgerPetersen
Last active July 5, 2024 17:29
Show Gist options
  • 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.

@fredantell
Copy link

fredantell commented Jul 5, 2024

Thank you to the author!! It was surprisingly hard finding directions like these.

For people doing a fresh install, running conda search qgis may not return any results. That means running conda install qgis won't work either. What follows helped me, although I don't use conda in my day to day so an expert can chime in with the corrected syntax if they'd like.

If conda install qgis complains nothing is found, you can run the following commands to add addition channels to check for packages:

conda config --add channels conda-forge
conda config --set channel_priority strict

If you want to install a specific version of qgis you can find it in conda search qgis now as mentioned.
Your command for installing it may have syntax like:

conda install qgis=3.34.6=py39h4cc71a7_1 -c conda-forge

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