{"id":7848,"library":"verlib2","title":"verlib2","description":"verlib2 is a Python library that provides a standalone bundle of version parsing implementations, specifically `distutils.version` (PEP 386) and `packaging.version` (PEP 440). Its primary purpose is to offer these functionalities without requiring the `packaging` library as a dependency, and to provide a solution for projects that relied on `distutils.version` after `distutils` was removed from the Python standard library in Python 3.12. It is actively maintained with a steady release cadence.","status":"active","version":"0.3.2","language":"en","source_language":"en","source_url":"https://github.com/pyveci/verlib2","tags":["versioning","PEP 386","PEP 440","distutils","packaging"],"install":[{"cmd":"pip install verlib2","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"The primary `Version` class in `verlib2` is the PEP 440 implementation, mirroring `packaging.version.Version` to avoid the `packaging` dependency.","wrong":"from packaging.version import Version","symbol":"Version","correct":"from verlib2 import Version"},{"note":"`distutils.version` was removed in Python 3.12. `verlib2` bundles its functionality to ensure compatibility.","wrong":"from distutils.version import LooseVersion","symbol":"LooseVersion","correct":"from verlib2.distutils.version import LooseVersion"},{"note":"`distutils.version` was removed in Python 3.12. `verlib2` bundles its functionality to ensure compatibility.","wrong":"from distutils.version import StrictVersion","symbol":"StrictVersion","correct":"from verlib2.distutils.version import StrictVersion"}],"quickstart":{"code":"from verlib2 import Version\nfrom verlib2.distutils.version import LooseVersion, StrictVersion\n\n# Using PEP 440 (packaging.version) style\nv1 = Version(\"1.0.dev456\")\nv2 = Version(\"1!1.2.rev33+123456\")\n\nassert v1 < v2\nassert Version(\"1.0\") == Version(\"1.0.0\")\n\n# Using PEP 386 (distutils.version) style\nlv1 = LooseVersion(\"1.2.3b1\")\nlv2 = LooseVersion(\"1.2.3\")\n\nassert lv1 < lv2\nassert LooseVersion(\"1.0\") != LooseVersion(\"1.0.0\") # Different behavior than PEP 440\n\ntry:\n    sv = StrictVersion(\"1.2.3.4\") # StrictVersion does not allow arbitrary suffixes\nexcept ValueError as e:\n    print(f\"StrictVersion error: {e}\")","lang":"python","description":"This quickstart demonstrates how to import and use both the PEP 440-compliant `Version` class and the PEP 386-compliant `LooseVersion` and `StrictVersion` classes for version comparison and parsing. It highlights the differences in parsing rules between the two standards, particularly regarding development suffixes and strictness."},"warnings":[{"fix":"Migrate `from distutils.version import LooseVersion` to `from verlib2.distutils.version import LooseVersion` (and similarly for `StrictVersion`).","message":"Direct imports from `distutils.version` will fail in Python 3.12 and later, as `distutils` was removed from the standard library.","severity":"breaking","affected_versions":"Python >=3.12"},{"fix":"Carefully choose the appropriate version class (`Version` for PEP 440, `LooseVersion` or `StrictVersion` for PEP 386) based on the specific versioning standard your project requires.","message":"The default `verlib2.Version` class implements PEP 440, which has different parsing and comparison rules than PEP 386 (implemented by `LooseVersion` and `StrictVersion`). For instance, PEP 440 treats `1.0` and `1.0.0` as equal, while PEP 386's `LooseVersion` considers them different.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Replace `from distutils.version import ...` with `from verlib2.distutils.version import ...`.","cause":"Attempting to import `distutils.version` in Python 3.12 or newer where `distutils` has been removed from the standard library.","error":"ModuleNotFoundError: No module named 'distutils.version'"},{"fix":"Ensure all values being compared are instances of `verlib2.Version` (or `LooseVersion`/`StrictVersion`). For example, `Version('1.0') < Version('2.0')`.","cause":"Attempting to compare a `verlib2.Version` object directly with a string. Version objects must be compared with other Version objects.","error":"TypeError: '<' not supported between instances of 'Version' and 'str'"}]}