What is the pythonic way of specifying a minimal module version?
<p>I'm writing a Python script where one of its imported modules needs to be at least version <code>x.y.z</code>.</p>

<pre><code>import pandas as pd

# Check the pandas version
_pdversion = map(lambda x: int(x), pd.__version__.split('.'))
if _pdversion[1] &lt; 18:
    # Not sure the most sensible exception class..
    raise Exception("ERROR: you need pandas &gt; version 0.18")
</code></pre>

<p>Is there a standard way to check for a minimal version at runtime? Or is this discouraged, in favour of specification at the package level and configure-time?</p>

<p>I think the most pythonic way would be to specify it in a requirements.txt file, and keep everything in a virtual environment.</p>

<p>Or: </p>

<pre><code>import pkg_resources
pkg_resources.require("requests==2.11.1")
import requests
</code></pre>

python dependencies packaging