Working with GRASS-7.0 and homebrew python on OS X

Published: Dec 25, 2015 by CarlosGrohmann

Sometimes getting all the software you need for Scientific analysis updated and running smoothly in OS X can be a bit annoying. For most things, there’s Homebrew (a nice post on setting your Mac for Scientific analysis with Python and homebrew is this one.) And if you’re into GIS, you probably know William Kyngesburye’s QGIS and GRASS packages. Michael Barton also provides GRASS packages, including the last stable version (7.0.2 at this moment). All seems good, but I started to have some problems because I wanted to have my Python stuff (Numpy, Scipy, Matplotlib, etc) updated via homebrew (to keep system python untouched) and then I tried to compile GRASS and QGIS with homebrew as well, but that didn’t worked out so well. The osgeo4mac formulas for ‘brewing’ QGIS are still for version 2.8 (the last stable is 2.12) and there is a ‘tap’ for GRASS 7, but despite compiling ok, I couldn’t get 3D viewing to work. Eventually I managed to get all working. This is how:

  1. Install python, numpy, scipy, matplotlib via homebrew.

  2. Install Michael Barton’s frameworks and GRASS 7.

  3. Install QGIS from William Kyngesburye.

  4. Edit your .bash_profile.

The last part is the tricky one. Homebrew install everything under /usr/local, and this needs to be in your PATH. The usual approach is to add this line to .bash_profile:

export PATH=/usr/local/bin:$PATH

Doing this will make homebrew’s python the one to be called if you type ‘python’ in a terminal window. But it will also change which python GRASS and QGIS will use. The thing is that both GRASS and QGIS packages are made to use OS X system python, not the one you installed with homebrew. The trick is to set a GRASS_PYTHON variable in .bash_profile, pointing to system python.

export GRASS_PYTHON=/System/Library/Frameworks/Python.framework/Versions/Current/bin/pythonw

Now, the really tricky thing is that GRASS_PYTHON must be called before setting the path for homebrew. So when you start GRASS, it will find the right python. Like this:

export GRASS_PYTHON=/System/Library/Frameworks/Python.framework/Versions/Current/bin/pythonw

export PATH=/usr/local/bin:$PATH

This got my setup working fine, with 3D view and all. And if you want to use homebrew’s python for analysis inside GRASS (with pygrass) you just have to call /usr/local/bin/python from GRASS’ terminal.

SIG grass osx mac python homebrew install

Share

Latest Posts

O que é um Invited Review?

Ultimamente recebemos no Brazilian Journal of Geology (BJGEO) alguns pedidos de autores interessados em enviar artigos de revisão, os “Invited Reviews”. Mas o que é esse tipo de artigo? Uma revisão bibliográfica de tese pode ser publicada dessa maneira? Vamos ver:

UTM 23S??

If there’s one thing that I see all the time as a reviewer, is a map of some study area in Brazil with a caption like “UTM coordinates zone 23S”.

FAQ about BJGEO

The Brazilian Journal of Geology is the official publication of the Brazilian Geological Society. As the Deputy Editor, I receive emails with common questions about the journal. So I decided to crate a page with some useful information for potential authors.