October 14th, 2004, 12:01 PM
#!/usr/bin/env python vs. #!/usr/bin/python
I am new to python but have writing perl and shell scripts for a long time now. I have always used these shebangs
so when I started writing Python it was just natural to do
Is there any reason why I should switch?
Does it really matter?
October 14th, 2004, 01:33 PM
If you use #!/usr/bin/python you are assuming that python is always installed in the /usr/bin directory - on some version of unix/linux it is installed elsewhere.
If you use #!/usr/bin/env python then it should run it wherever it is on the path. This should make your script more portable.
However for CGI scripts it is better to specify the full path to python, since the PATH variable may not be set for the CGI script.
Dave - The Developers' Coach
October 14th, 2004, 02:50 PM
#!/usr/bin/python only works with some Linux distros (RedHat). It doesn't work on my FreeBSD, NetBSD or OpenBSD boxes. For these boxes, python is installed elsewhere (/usr/local/bin or /usr/pkg/bin), since it doesn't come with these systems by default. #!/usr/bin/env python works everywhere. Incidentally, I borrowed that idea for my perl scripts too (since NetBSD doesn't have perl installed by default either)
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne
"I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo