Skip to content

Instantly share code, notes, and snippets.

@tintinweb
Last active January 26, 2017 15:58
Show Gist options
  • Save tintinweb/65e7a893d6d07363b64af1ee27e7181c to your computer and use it in GitHub Desktop.
Save tintinweb/65e7a893d6d07363b64af1ee27e7181c to your computer and use it in GitHub Desktop.
Try to inplace upgrade from python 2.5 to 2.7
#!/usr/bin/env python2
'''
# ./inplace-upgrade.py
python version: (2, 5, 2, 'final', 0)
[***] newer python interpreter available. switching versions...
python version: sys.version_info(major=2, minor=7, micro=9, releaselevel='final', serial=0)
'''
import os, sys
def try_switch_to_python2_7():
py27 = "/usr/bin/python2.7"
if sys.version_info < (2,7) and os.path.exists(py27):
print "[***] newer python interpreter available. switching versions... "
os.execve(py27,[py27]+sys.argv,os.environ)
sys.exit()
print "python version: ", sys.version_info
try_switch_to_python2_7()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment