Bug report #6015

Sextante on Mac OS X: a working solution for running GRASS commands

Added by Martin Laloux about 2 years ago. Updated over 1 year ago.

Status:Closed Start Date:07/11/2012
Priority:High Due date:
Assigned to:Victor Olaya % Done:

0%

Category:Processing-Backend/GRASS
Target version:-
Patch supplied:Yes Tag:

Description

I could not use the Grass commands on Mac OS X. So I decided to analyze the Python scripts and the sextante log to understand why they did not work.
The log gave me the error
"GRASS execution console output|/bin/sh: grass64: command not found"
and This problem is due to the line 249 of the script GrassUtils.py
command = "grass64 " + GrassUtils.grassMapsetFolder() + "/user"

GRASS GIS from William Kyngesburye (http://www.kyngchaos.com/) is an application bundle on Mac OS X.
A bundle is a directory that allows related resources such as an application's executable and its libraries, graphics, help files, etc. to be grouped together, appearing as a single file to the user (GRASS-6.4.app). The Unix executables are in the bundle and not in /usr/bin like on Linux
The path on Mac OS X is :
/Applications/GRASS-6.4.app/Contents/MacOS/grass.sh

The solution is therefore to replace the line 249 of GrassUtils.py by
command = "/Applications/GRASS-6.4.app/Contents/MacOS/grass.sh " + GrassUtils.grassMapsetFolder() + "/user"

and everything works fine.

History

Updated by Martin Laloux about 2 years ago

For the Help files the the solution is very simple, just put

GRASS_HELP_FOLDER=/Applications/GRASS-6.4.app/Contents/MacOS/docs/html

in sextante_qgis.conf file

Updated by Martin Laloux about 2 years ago

  • Category set to Processing-Backend/GRASS
  • Assigned to set to Victor Olaya

Updated by Martin Laloux about 2 years ago

The definitive solution is in GrassUtils.py:

def executeGrass(commands, progress):
if SextanteUtils.isWindows():
[...]
else:
gisrc = SextanteUtils.userFolder() + os.sep + "sextante.gisrc"
os.putenv("GISRC", gisrc)
os.putenv("GRASS_MESSAGE_FORMAT", "gui")
os.putenv("GRASS_BATCH_JOB", GrassUtils.grassBatchJobFilename())
GrassUtils.createGrassBatchJobFileFromGrassCommands(commands)
os.chmod(GrassUtils.grassBatchJobFilename(), stat.S_IEXEC | stat.S_IREAD | stat.S_IWRITE)
if SextanteUtils.isMac():
command = "/Applications/GRASS-6.4.app/Contents/MacOS/grass.sh " + GrassUtils.grassMapsetFolder() + "/user"
else:
command = "grass64 " + GrassUtils.grassMapsetFolder() + "/user"
gisrc = SextanteUtils.userFolder() + os.sep + "sextante.gisrc"
os.putenv("GISRC", gisrc)
os.putenv("GRASS_MESSAGE_FORMAT", "gui")
os.putenv("GRASS_BATCH_JOB", GrassUtils.grassBatchJobFilename())
GrassUtils.createGrassBatchJobFileFromGrassCommands(commands)
os.chmod(GrassUtils.grassBatchJobFilename(), stat.S_IEXEC | stat.S_IREAD | stat.S_IWRITE)
.....

Updated by Victor Olaya about 2 years ago

  • Status changed from Open to Feedback

Before adding this change, one question: is there no way of having GRASS installed in a different folder in Mac OS?? If so, maybe I can add it as an option to be set by the user (as it happens when you are running SEXTANTE for QGIS in Windows), with the default value of that folder that you indicate.

Updated by Martin Laloux about 2 years ago

The couple QGIS - GRASS GIS of William Kyngesburye (www.kyngchaos.com/) is the most popular and and the most used. The QGIS version use exclusively the corresponding GRASS implementation (for the QGIS plugin). It is best suited to the classic Mac users, two applications.

There are of course other solutions mush more "Linux like" and much less popular, installed by package management systems:
- Fink (http://www.finkproject.org/index.php?phpLang=en) installs the executable of GRASS GIS in /sw/bin
- MacPorts (http://www.macports.org/) installs the executable of GRASS GIS in /opt/bin
- Homebrew (http://mxcl.github.com/homebrew/) installs a symbolic link of the executable of GRASS GIS in /usr/local/bin

but these solutions adjusts the PATH environment variable (/sw/bin/grass64, /opt/bin/grass64) or /usr/local/bin/grass64.

Updated by Martin Laloux about 2 years ago

and therefore, the solution you propose is the best (for those who do not know Python). With SextanteUtils.isMac() it is possible to know that you are on Mac but but find the version of Grass you are using is very difficult... and QGIS does not recognize environment variables or alias defined in .bash_profile or .bashrc.

For example, i have an alias in my .bash_profile
alias grass64=/Applications/GRASS-6.4.app/Contents/MacOS/grass.sh

that works in the shell but not in QGIS

Updated by Victor Olaya about 2 years ago

  • Status changed from Feedback to Resolved

Already fixed. Now the folder can be set by the user, but it defaults to the proposed location. The same happens with the help folder

Updated by Martin Laloux about 2 years ago

many thanks

Updated by Giovanni Manghi over 1 year ago

  • Status changed from Resolved to Closed

reopen if necessary.

Also available in: Atom PDF