[GIS] Clean way to install gdaltools plugin for QGIS on OSX

gdalqgis

I have qgis 1.8.0 on osx mountain lion and am installing the gdaltools 1.2.29. I have run into a problem that a number of people are seeing. The plugin cannot find my gdal python (see below).

Anyway, I can fix the problem hackily (if that is a word) by symlinking

  cd /Library/Python/2.7
  sudo mv site-packages/ site-packages-old
  sudo ln -s /Library/Frameworks/GDAL.framework/Versions/1.9/Python/2.7/site-packages /Library/Python/2.7

So that fixes the prob because the python path list that the plugin knows about includes /Library/Python/2.7/site-packages But the real solution is to add a path to the list of paths that the python plugin[s] know about. How do you do that?

—-start of error message—-

Couldn't load plugin GdalTools due an error when calling its classFactory() method

Traceback (most recent call last):
File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 164, in startPlugin
plugins[packageName] = package.classFactory(iface)
File "/Users/aberezin/.qgis//python/plugins/GdalTools/init.py", line 32, in classFactory
from GdalTools import GdalTools
File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 309, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
File "/Users/aberezin/.qgis//python/plugins/GdalTools/GdalTools.py", line 39, in
raise ImportError( error_str )
ImportError: No module named osgeo [python-gdal]

Python version:
2.7.2 (default, Jun 20 2012, 16:23:33)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)]

QGIS version:
1.8.0-Lisboa Lisboa,

Python path: ['/Applications/QGIS.app/Contents/MacOS/../Resources/python', '/Users/aberezin/.qgis//python', '/Users/aberezin/.qgis//python/plugins', '/Applications/QGIS.app/Contents/MacOS/../Resources/python/plugins', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC']

Best Answer

Alan,

The path to gdal's Python bindings is missing because Apple seems to remove anything in the system site-packages folder during upgrade to Mt. Lion (thank-you-very-much Apple).

There is a thread in the QGIS User mailing list about this, and gdal in particular. You basically have to reinstall all previously installed Python packages, or possibly copy them over from a pre-Mt. Lion upgrade backup.

However, first you must undo what you did when creating your symbolic link to the gdal framework subdirectory: remove the link and rename site-packages-old back to site-packages. You definitely do not want to rename the site-packages folder of your Python installation, or point it to a specific library's install.

After you have your gdal/osgeo Python support reinstalled, GdalTools, which is a separate core plugin that is part of QGIS, as Giovanni noted, should work fine.

Related Question