[GRASS-dev] PYTHONPATH question

Michael Barton michael.barton at asu.edu
Sun Jul 27 19:39:20 EDT 2008



On Jul 27, 2008, at 4:01 PM, Glynn Clements wrote:

>
> Michael Barton wrote:
>
>> Any idea why the following PYTHONPATH in my .profile works fine for
>> GRASS finding packages like MatPlotLib and a version with the site-
>> packages entry last does not?
>>
>> PYTHONPATH="/Library/Frameworks/Python.framework/Versions/2.5/lib/
>> python2.5/site-packages:/Library/Frameworks/Python.framework/ 
>> Versions/
>> 2.5/lib/python25.zip:/Library/Frameworks/Python.framework/Versions/ 
>> 2.5/
>> lib/python2.5:/Library/Frameworks/Python.framework/Versions/2.5/lib/
>> python2.5/plat-darwin:/Library/Frameworks/Python.framework/Versions/
>> 2.5/lib/python2.5/plat-mac:/Library/Frameworks/Python.framework/
>> Versions/2.5/lib/python2.5/plat-mac/lib-scriptpackages:/Library/
>> Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-tk:/ 
>> Library/
>> Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-
>> dynload:"$PYTHONPATH
>
> Why do you have all of your Python system directories in PYTHONPATH?
> Those should already be in sys.path.
>
> FWIW, on Gentoo, the only directory which is added to PYTHONPATH by
> the OS configuration is /usr/lib/portage/pym ("portage" is Gentoo's
> package manager, and it's written mainly in Python).
>
> I suggest completely unsetting PYTHONPATH, and seeing what problems
> (if any) that causes.

Interesting. This was something the Mac Python installation puts in,  
though I can tell it not to do so. If I unset this, Python works fine  
from a terminal and importing in the Python interpreter works fine too.

BUT, there are problems in GRASS because Init.sh now sets $PYTHONPATH  
to $GISBASE/etc. This is fine for grass.py, but it causes problems  
accessing anything else in site-packages. Here is the result of  
running one of the MatPlotLib demo scripts.

GRASS 7.0.svn (Spearfish60_test):~ > histogram_mpldemo.py
Traceback (most recent call last):
   File "/Applications/Grass/GRASS-7.0.app/Contents/MacOS/scripts/ 
histogram_mpldemo.py", line 94, in <module>
     import matplotlib
ImportError: No module named matplotlib

It's looking for matplotlib in $GISBASE/etc now.

Michael



More information about the grass-dev mailing list