Identify the minimum Python version required for a given script
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

pyqver - query required Python version

Greg Hewgill


This script attempts to identify the minimum version of Python that is required to execute a particular source file.

When developing Python scripts for distribution, it is desirable to identify which minimum version of the Python interpreter is required. pyqver attempts to answer this question using a simplistic analysis of the output of the Python compiler.

When run without the -v argument, sources are listed along with the minimum version of Python required. When run with the -v option, each version is listed along with the reasons why that version is required. For example, for the script itself:
        2.3     platform

This means that uses the platform module, which is a 2.3 feature.

The script is specific to Python 2.x, and is specific to Python 3.x.

This script was inspired by the following question on Stack Overflow: Tool to determine what lowest version of Python required?


This script requires at least Python 2.3.


Usage: pyqver[23].py [options] source ...

    Report minimum Python version required to run given source files.

    -m x.y or --min-version x.y (default M.N)
        report version triggers at or above version x.y in verbose mode
    -l or --lint
        print a lint style report showing each offending line
    -v or --verbose
        print more detailed report of version triggers for each version

M.N is the default minimum version depending on whether or is run.


There are currently a few features which are not detected. For example, the 2.6 syntax

    # ...
except Exception as x:
    # ...

is not detected because the output of the compiler module is the same for both the old and the new syntax.

The TODO file has a few notes of things to do.