15

I'm working on a new server for a new workplace, and I'm trying to reuse a CGI script I wrote in Python earlier this year. My CGI script starts off with

#!/local/usr/bin/python

But when I run this on the new server, it complains that there's no such folder. Obviously Python's kept in a different place on this box, but I've got no idea where.

I haven't done much unix before, just enough to get around, so if there's some neat trick I should know here I'd appreciate it :)

Thanks!

Josh Lee
  • 171,072
  • 38
  • 269
  • 275
Adam
  • 482
  • 1
  • 4
  • 12
  • 2
    You might want to ask these kinds of questions on unix.stackexchange.com. It's perfectly acceptable here, but unix a good place for these specific not-quite-programming-but-programming-related questions – Falmarri Dec 07 '10 at 04:40

6 Answers6

30

Try:

which python

in a terminal.

icyrock.com
  • 27,952
  • 4
  • 66
  • 85
9

For this very reason it is recommend that you change your shebang line to be more path agnostic:

#!/usr/bin/env python

See this mailing list message for more information:

Consider the possiblities that in a different machine, python may be installed at /usr/bin/python or /bin/python in those cases, #!/usr/local/bin/python will fail. For those cases, we get to call the env executable with argument which will determine the arguments path by searching in the $PATH and use it correctly.

(env is almost always located in /usr/bin/ so one need not worry that env is not present at /usr/bin.)

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • Even on the same machine, when using [virtualenv](http://pypi.python.org/pypi/virtualenv) the interpreter path will change. – Petr Viktorin Feb 13 '11 at 11:12
4
# which python
/usr/local/bin/python

Update:

I misread. Replace your header with

#!/usr/bin/env python

This will pull in the python location from the user that runs the script's environmental settings

Falmarri
  • 47,727
  • 41
  • 151
  • 191
4

Try: which python or whereis python

SiegeX
  • 135,741
  • 24
  • 144
  • 154
3

It is a good idea to use backticks for header Python script:

`which python`
Yuda Prawira
  • 12,075
  • 10
  • 46
  • 54
1

The proper way to solve this problem is with

#!/usr/bin/env python

which allows for the use of a binary in the PATH in a shebang.

Josh Lee
  • 171,072
  • 38
  • 269
  • 275