Stupid question: Making scripts python-scripts

Benjamin Niemann pink at odahoda.de
Thu Jul 21 14:17:07 EDT 2005


Jan Danielsson wrote:

> Hello all,
> 
>    How do I make a python script actually a _python_ in unix:ish
> environments?
> 
> I know about adding:
> #!/bin/sh
> 
>    ..as the first row in a shell script, but when I installed python on
> a NetBSD system, I didn't get a "python" executable; only a "python2.4"
> executable.
> 
>    Adding "#!/usr/pkg/bin/python2.4" as the first row in the script
> would probably work, but that would be too specific for the system I'm
> using, imho.
> 
>    I saw someone using "#!/usr/bin/env python", but that failed on the
> system I'm using, so I assume that's something specific too (or is the
> installation broken?).

You could 
a) create a symlink to your python executable in a well known location, e.g.
 ln -s /usr/pkg/bin/python2.4 /usr/bin/python
And use either "#!/usr/bin/python" (which should work on most UNIXoid
systems with python installed) or "#!/usr/bin/env python"

b) use the absolute path /usr/pkg/bin/python2.4 for your script (in order to
have it running on your system) and use distutils to create a setup.py
script for distribution. IIRC setup.py will recognize the shebang of your
scripts and replace it with the proper path to python of the target system
during installation.

-- 
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://www.odahoda.de/



More information about the Python-list mailing list