Fixing Python path for QGIS scripting on Mac OSX

Mar 22, 2013 • CarlosGrohmann

So, QGIS 1.8 ‘Lisboa’ is out! Lots of cool new features, and lots of fixes. Check out the oficial release here.

And since Kyngchaos updated his Mac OSX packages, I went for an upgrade. After a clean removal of version 1.7 (using the awesome AppCleaner), I upgraded both the complete GDAL and QGIS.

After installing, time to set things right. Type this in a terminal:
$ export DYLD_LIBRARY_PATH=/Applications/QGIS.app/Contents/MacOS/lib/:/Applications/QGIS.app/Contents/Frameworks/
$ export PYTHONPATH=/Applications/QGIS.app/Contents/Resources/python/

Now test it:

$ python  
Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05)  
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin  
Type "help", "copyright", "credits" or "license" for more information.  
>>> import qgis.core  
>>> import qgis.gui  
>>> import PyQt4.QtCore  
>>> import PyQt4.QtGui

Nice! While you’re at it, set the path for you command-line GDAL programs:
export PATH=/Library/Frameworks/GDAL.framework/Programs:$PATH

Now, this will only work in the current terminal session. To make it permanent, add these lines to your .bash_profile