[GRASS-dev] PYTHONPATH question
Michael Barton
michael.barton at asu.edu
Sun Jul 27 20:40:55 EDT 2008
On Jul 27, 2008, at 5:19 PM, Glynn Clements wrote:
>
> Michael Barton wrote:
>
>>>> 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)
> ?
/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-
packages/setuptools-0.6c8-py2.5.egg
/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-
packages/Dabo-0.8.3-py2.5.egg
/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-
packages/setuptools-0.6c8-py2.5.egg
/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-
packages/ipython-0.8.4-py2.5.egg
/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-
packages/numpy-1.1.0-py2.5-macosx-10.3-i386.egg
/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-
packages/matplotlib-0.98.1-py2.5-macosx-10.3.egg
/Applications/Grass/GRASS-7.0.app/Contents/MacOS/etc/python
/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-
packages
/usr/local/lib/wxPython-unicode-2.8.8.1/lib/python2.5/site-packages
/usr/local/lib/wxPython-unicode-2.8.8.1/lib/python2.5/site-packages/
wx-2.8-mac-unicode
/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-
dynload
/usr/local/lib/wxPython-unicode-2.8.8.1/lib/python2.5
/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
>
>
> When you say that you can tell the Mac Python installer not to set
> PYTHONPATH, do you know if does something else instead?
No. It simply has an option (default, but can turn off) to
modify .profile.
>
>
> Is "python" the actual executable, or is it a front-end script?
/usr/bin/python and /usr/local/bin/python are symlinks to /Library/
Frameworks/.../python2.5, which is an executable. I've checked and
this is the only "python" in my path
> 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).
I don't think so. It works fine when just calling the python
interpreter from the shell. I think the issue is now just down to the
fact that Init.sh creates a $PYTHONPATH that has $GISBASE/etc/python.
Once this is created, the python side of g.parser only looks for
modules to import in $PYTHONPATH. If I just invoke python from the
GRASS shell to start the interpreter, there is no problem importing
matplotlib or anything else. It's only having parsing import
matplotlib when it's in a script. This is an improvement over previous
complications. I really appreciate your help.
Michael
>
>
> --
> Glynn Clements <glynn at gclements.plus.com>
More information about the grass-dev
mailing list