Provided running python
or python2
does the right thing (preferably test this as the user the cgi script will run as if you can), the convention is to use the program env
- which can search $PATH
for an executable instead of hard coding a path. env
is a standard program on any Unix-like system, which is always in /usr/bin unless your base system is very strange, so you can do this:
#!/usr/bin/env python
According to this previous answer, this would cause the line to be ignored on a Windows machine, which may be what you want - it will cause Apache to revert to other ways to find an appropriate interpreter, which seems to include the value of a registry key (at HKEY_CLASSES_ROOT\.cgi\Shell\ExecCGI\Command
for cgi files, and change the extension as appropriate), and likely includes Windows' standard lookup rules if that key is unset.