At the beginning of all my executable Python scripts I put the shebang line:
#!/usr/bin/env python
I'm running these scripts on a system where env python
yields a Python 2.2 environment. My scripts quickly fail because I have a manual check for a compatible Python version:
if sys.version_info < (2, 4):
raise ImportError("Cannot run with Python version < 2.4")
I don't want to have to change the shebang line on every executable file, if it's possible; however, I don't have administrative access to the machine to change the result of env python
and I don't want to force a particular version, as in:
#!/usr/bin/env python2.4
I'd like to avoid this because system may have a newer version than Python 2.4, or may have Python 2.5 but no Python 2.4.
What's the elegant solution?
[Edit:] I wasn't specific enough in posing the question -- I'd like to let users execute the scripts without manual configuration (e.g. path alteration or symlinking in ~/bin
and ensuring your PATH has ~/bin
before the Python 2.2 path). Maybe some distribution utility is required to prevent the manual tweaks?