Python - utility program to check module availability
<p>Is there a command line(preferably) utility program that lists all <code>major</code> versions of python that come bundled with a particular module in that version's library? </p>

<p>For example <code>json</code> module is only available in versions 2.6+</p>

<p>So running this utility should list:</p>

<pre><code>2.6
2.7
.. and the 3.x versions
</code></pre>

<p>There is no such built-in command.</p>

<p>If having an internet connection is not an issue you can simply check the url at <code>https://docs.python.org/&lt;version-number&gt;/library/&lt;module-name&gt;.html</code>:</p>

<pre><code>from urllib.request import urlopen
from urllib.error import HTTPError


def has_module(version, module_name):
    try:
        urlopen('https://docs.python.org/{}/library/{}.html'.format(version, module_name))
    except HTTPError as e:
        if e.code == 404:
            return False
        raise e
    return True
</code></pre>

<p>Example usage:</p>

<pre><code>In [2]: has_module('2.7', 'asyncio')
Out[2]: False

In [3]: has_module('3.3', 'asyncio')
Out[3]: False

In [4]: has_module('3.4', 'asyncio')
Out[4]: True
</code></pre>

<p>Must be run in python3, but a python2 version isn't hard to write.</p>

<p>If you want an offline tool you can always parse the page <code>https://docs.python.org/&lt;version-number&gt;/library/index.html</code> and obtain a list of module pages for that python version and then just build a <code>dict</code> that maps the python version to the set of available modules.</p>

python python-3.x