def smoke_python_name(): # if this script is being run by py2.5 or greater, # then we assume that "python" points to a 2.5 or # greater python VM. otherwise, explicitly use 2.5 # which we assume to be installed. import subprocess version = re.compile(r'[Pp]ython ([\d\.]+)', re.MULTILINE) binaries = ['python2.5', 'python2.6', 'python2.7', 'python25', 'python26', 'python27', 'python'] for binary in binaries: try: # py-2.4 compatible replacement for shell backticks print 'about to try %s' % binary out, err = subprocess.Popen([binary, '-V'], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() print 'subprocess executed for %s' % binary for stream in (out, err): match = version.search(stream) if match: print '%s matched' % binary versiontuple = tuple(map(int, match.group(1).split('.'))) if versiontuple >= (2, 5): return binary print '%s did not match' % binary except Exception, e: print 'got exception %s when trying %s' % (e, binary) pass # if that all fails, fall back to "python" return "python" ======================================================================== OUTPUT : ======================================================================== scons: Reading SConscript files ... scons version: 2.1.0 python version: 2 7 2 'final' 0 using system version of: snappy using system version of: sm using system version of: pcre Checking whether the C++ compiler worksyes Checking for C library stdc++... yes Checking for C++ header file boost/filesystem/operations.hpp... yes Checking for C library boost_system-mt... yes Checking for C library boost_thread-mt... yes Checking for C library boost_filesystem-mt... yes Checking for C library boost_program_options-mt... yes Checking for C++ header file execinfo.h... yes Checking for C library pcap... yes Checking whether the C++ compiler worksyes Checking for C++ header file boost/filesystem/operations.hpp... yes Checking for C library boost_system-mt... yes Checking for C library boost_thread-mt... yes Checking for C library boost_filesystem-mt... yes Checking for C library boost_program_options-mt... yes Checking for C++ header file execinfo.h... yes Checking for C library pcap... yes about to try python2.5 got exception [Errno 2] No such file or directory when trying python2.5 about to try python2.6