tags:

views:

25

answers:

1

I am currently running a Python scripts both on Linux and Windows 7. The file is executed in an execv style with which I mean that the interpreter is defined in the beginning of the file in a command.

In Windows system, the interpreter specification is:

#!C:\Python26\python.exe

However in Linux this needs to be

#!/usr/bin/python

I would like to run this script in both systems without having to change this line again and again.

I have tried out the following:

#!C:\Python26\python.exe
#!/usr/bin/python

as well as:

#!C:\Python26\python.exe;/usr/bin/python

So: is there any way I could specify multiple interpreters?

+1  A: 
#!/usr/bin/env python

That will call the env program to search your PATH for a Python executable.

If you need to ensure a specific version of Python you can do e.g.:

#!/usr/bin/env python2.5
Adam Bernier
Nice! Should this work on Windows as well?
jsalonen
@jsalonen Windows doesn't use the shebang line to determine what to run the file with. The standard Python installer for Windows sets it up so you can run .py/.pyw files from the command line just like any other executable, so you shouldn't need to worry about Windows.
Liquid_Fire
The point being that I don't have /usr/bin/env available on Windows
jsalonen
@jsalonen: The point being that they're *different* operating systems and have almost *nothing* in common. What you're asking for cannot be done across operating systems.
S.Lott