[GRASS-dev] PYTHONPATH question

Glynn Clements glynn at gclements.plus.com
Sun Jul 27 20:19:49 EDT 2008


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.

Any directories in PYTHONPATH should be in addition to the Python
system directories, not instead of them.

What do you get from:

	import sys
	print '\n'.join(sys.path)
?

When you say that you can tell the Mac Python installer not to set
PYTHONPATH, do you know if does something else instead?

Is "python" the actual executable, or is it a front-end script?

I'm wondering whether python is being invoked with the -S switch,
which suppresses the automatic "import site" (which causes
site-packages to be added to sys.path, along with any subdirectories
referenced by any site-packages/*.pth files).

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-dev mailing list