1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Rep Power

    #!/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?

  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    London, England
    Rep Power
    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
  4. #3
  5. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Woodland Hills, Los Angeles County, California, USA
    Rep Power
    #!/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

IMN logo majestic logo threadwatch logo seochat tools logo