title: Python version number comparison with != (not equal)
body: <p>I'm trying to write a function which replicates the behaviour of <a href="https://packaging.python.org/guides/distributing-packages-using-setuptools/#python-requires" rel="nofollow noreferrer"><code>python_requires</code></a> from <code>setup.py</code>, because I failed to find the implementation in the source code of setuptools and pip. Comparing version numbers in Python <a href="https://stackoverflow.com/a/11887885">should be easy enough</a>, I'm using <a href="https://packaging.pypa.io/en/latest/version.html" rel="nofollow noreferrer">packaging.version</a> which does all the work for me, except...</p>
  <p>Let's look at a version string like <code>&quot;&gt;=2.6, !=3.0.*, !=3.1.*&quot;</code>. I split at every comma, then look at each comparison individually:</p>
  <pre><code>from packaging import version
  version.parse(&quot;3.0.5&quot;) &gt;= version.parse(&quot;2.6&quot;)
  </code></pre>
  <p>Version 3.0.5 is greater than 2.6, as expected. Next:</p>
  <pre><code>version.parse(&quot;3.0.5&quot;) != version.parse(&quot;3.0.*&quot;)
  </code></pre>
  <p>This returns True (i.e. <code>3.0.5</code> is <em>not</em> the same as <code>3.0.*</code>), but version <code>3.0.5</code> should actually match <code>3.0.*</code>. Is there a standard way in Python to check if a version number with wildcards matches another version number?</p>
  <p><em>edit</em>: also related, how would I implement a compatible version matcher, like <code>~= 3.0.5</code>, which should match any version <code>&gt;= 3.0.5</code> but <code>&lt; 3.1.0</code>?</p>
  <p>It looks like I'm trying to implement the version specifiers of <a href="https://www.python.org/dev/peps/pep-0440/#version-specifiers" rel="nofollow noreferrer">PEP 440</a> here...</p>