Chapter 27. Miscellaneous Functionality

SCons supports a lot of additional functionality that doesn't readily fit into the other chapters.

27.1. Verifying the Python Version: the EnsurePythonVersion Function

Although the SCons code itself will run on any 2.x Python version 2.4 or later, you are perfectly free to make use of Python syntax and modules from more modern versions (for example, Python 2.5 or 2.6) when writing your SConscript files or your own local modules. If you do this, it's usually helpful to configure SCons to exit gracefully with an error message if it's being run with a version of Python that simply won't work with your code. This is especially true if you're going to use SCons to build source code that you plan to distribute publicly, where you can't be sure of the Python version that an anonymous remote user might use to try to build your software.

SCons provides an EnsurePythonVersion function for this. You simply pass it the major and minor versions numbers of the version of Python you require:

EnsurePythonVersion(2, 5)
    

And then SCons will exit with the following error message when a user runs it with an unsupported earlier version of Python:

% scons -Q
Python 2.5 or greater required, but you have Python 2.3.6