[GRASS-dev] PYTHONPATH question

Glynn Clements glynn at gclements.plus.com
Tue Jul 29 16:03:45 EDT 2008


Michael Barton wrote:

> > It looks like, when run from a python script in GRASS, you're  
> > getting the system python.
> >
> > Yet, when you run python itself from GRASS, you get the python.org  
> > Python.  What is the shebang line (first line) in your python  
> > script, it may be pointing to the system python?
> >
> >
> > On Jul 27, 2008, at 7:40 PM, Michael Barton wrote:
> >
> >>> 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
> >
> > /usr/bin/python should be a symlink to the SYSTEM python.
> 
> 
> Weird. When I do 'show original' for /usr/bin/python, it shows as a  
> symlink to
> 
> /System/Library/Frameworks/Python.framework/Versions/2.5/bin/python
> 
> ...which is a symlink to /System/Library/Frameworks/Python.framework/ 
> Versions/2.5/bin/python2.5
> 
> BUT, if I start it...
> 
> cmb-MBP-2:~ cmbarton$ python
> Python 2.5.2 (r252:60911, Feb 22 2008, 07:57:53)
> [GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
>  >>>
> cmb-MBP-2:~ cmbarton$ /usr/bin/python
> Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:17)
> [GCC 4.0.1 (Apple Inc. build 5465)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
>  >>> ^D
> cmb-MBP-2:~ cmbarton$ /usr/bin/python2.5
> Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:17)
> [GCC 4.0.1 (Apple Inc. build 5465)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
>  >>>
> cmb-MBP-2:~ cmbarton$ /usr/local/bin/python
> Python 2.5.2 (r252:60911, Feb 22 2008, 07:57:53)
> [GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
>  >>>
> 
> So it IS the shebang at the top.

Is "python" an alias? In the shell, type "alias python" and
"type python".

> So what to do to make this work?
> 
> #!/usr/bin/env python ????
> 
> This works on my Mac. Does it work for others?

The use of /usr/bin/env is a hack to make it look for "python" in
$PATH. The #! syntax requires an absolute path, but there's no telling
where python will be installled (Python isn't part of POSIX, so you
can't rely up on it being installed in /usr/bin).

The actual purpose of env is to run commands with a modified
environment. The reason it's being used here (without any environment
changes) is just because it allows the program to run to be specified
as a name rather than a full path, and because /usr/bin/env will
always be available.

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


More information about the grass-dev mailing list