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:
JavaScript
x
2
1
#!C:Python26python.exe
2
However in Linux this needs to be
JavaScript
1
2
1
#!/usr/bin/python
2
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:
JavaScript
1
3
1
#!C:Python26python.exe
2
#!/usr/bin/python
3
as well as:
JavaScript
1
2
1
#!C:Python26python.exe;/usr/bin/python
2
So: is there any way I could specify multiple interpreters?
Advertisement
Answer
JavaScript
1
2
1
#!/usr/bin/env python
2
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.:
JavaScript
1
2
1
#!/usr/bin/env python3.11
2