How to install GDAL and QGIS on macOS Catalina
--
Due to lots of issues found trying to install this components for geo-spatial analysis, I will explain an easy way to install GDAL (Geospatial Data Abstraction Library) and QGIS (a free and open source Geographic Information System) on a macOS Catalina 10.15 environment. In theory, it works for others version like Mojave but I have no tested yet.
The last version of GDAL/OGR was 3.0.4 when I decided to write this and the version of QGIS we are going to install is 3.12.1. Thinking in python developers like me who want to setup a GDAL Python bindings on Mac, I chose a stable version of GDAL (2.4.4) to be compatible with most of the geospatial and data science libraries.
Just for reproducing this, am using a Macbook Air, with Python version 3.7.3.
That said, Let’s begin
There are multiple methods for installation, I guess the easier way to install this without too much command lines in a terminal is installing it via Anaconda
# You don't need to run this command
conda install -c conda-forge gdal
GDAL is included in the Anaconda distribution, in case you want to upgrade the command above will install the last version of GDAL (3.0.4) or the last version found at https://anaconda.org/conda-forge/gdal
Alternatively, install GDAL via brew:
- Install HomeBrew
Just copy and paste the line below in a terminal, and press enter.
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2. Install GDAL via brew
Install the headers files first to avoid GDAL fail.
% brew install gdal --HEAD
GDAL will fail installing if expected version of the dependence is not present in the system.
Now install GDAL
% brew install gdal
To be sure that GDAL is installed in your system, just type:
% gdal-config --version
2.4.4
If you get any error, just try to open a new terminal. Also If you want to see what version of GDAL and its dependencies are being installed in your system with Hombrew, just check it out at https://formulae.brew.sh/formula/gdal
3. GDAL Python binding
Now we have GDAL installed, we proceed to setup a GDAL Python binding. Just upgrade your version of pip before to install the library in python environment.
pip3 install — upgrade pip
Once updated, just type:
pip3 install gdal==2.4.4
Note the GDAL version of the end of the command, it must be the same as the obtained in the step above using gdal-config. To avoid conflicts or any further issues, it’s important to install and use the exact versions that any component will require.
Sometimes you could experiment ModuleNotFoundError trying to install the GDAL python binding, you can solve this issue installing the needed modules. The most required module is Numpy, and you can install it just typing:
pip3 install numpy
# or brew install numpy instead
4. Check out your GDAL python binding
python3 -c “from osgeo import gdal”
You won’t see any thing if everything is well installed, or just type the following command to get the gdal version (2040400):
python3 -c ‘import gdal; print(gdal.VersionInfo())’
Do not forget your GDAL environment was installed in /usr/local/Cellar/gdal/ for further configurations.
You also can type gdal + tab and see more GDAL commands:
5. Install QGIS
After this, we can finally install QGIS version 3.12.1 București. Just go to the QGIS website at https://qgis.org/en/site/ and download it.
If you have different gdal and python version installed, you need to choose the right version of QGIS at https://qgis.org/en/site/forusers/alldownloads.html
Also you can see a message with Catalina security issue, due to QGIS is not notarized according to the Apple politics, similar to:
Then you need to right-click on open, and then open again this does force open on mac. You can also allow the app in security preferences.
That’s it for now! and I hope it helps.
There are much more info at https://gis.stackexchange.com or https://stackoverflow.com/search?q=GDAL if you find any issue installing different versions of Python, GDAL and QGIS.
Stay tune! to get skills using this platform and learn about Geospatial Data Science in python.