{"id":4370,"library":"looseversion","title":"LooseVersion","description":"The `looseversion` package is a backwards/forwards-compatible fork of `distutils.version.LooseVersion`, designed for comparing heterogeneous version schemes that do not strictly follow PEP 440. It offers an identical interface and comparison logic to the original, with the main enhancement being comparability between `looseversion.LooseVersion` and `distutils.version.LooseVersion` instances. The current version is 1.3.0, released on July 5, 2023, and it aims to be a stable replacement for the deprecated `distutils` version class, with a relatively low release cadence focused on compatibility and maintenance.","status":"active","version":"1.3.0","language":"en","source_language":"en","source_url":"https://github.com/effigies/looseversion","tags":["versioning","comparison","distutils","compatibility"],"install":[{"cmd":"pip install looseversion","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"note":"The `distutils.version.LooseVersion` class is deprecated and will be removed in Python 3.12 and later. The `looseversion` package provides a direct, compatible replacement.","wrong":"from distutils.version import LooseVersion","symbol":"LooseVersion","correct":"from looseversion import LooseVersion"}],"quickstart":{"code":"from looseversion import LooseVersion\n\nv1 = LooseVersion(\"1.0.0\")\nv2 = LooseVersion(\"2.0.0\")\n\nprint(f\"'{v1}' < '{v2}' is {v1 < v2}\")\nprint(f\"'{v1}' < '2' is {v1 < '2'}\")","lang":"python","description":"Demonstrates basic version object creation and comparison, including comparison with a string literal."},"warnings":[{"fix":"Change import statements from `from distutils.version import LooseVersion` to `from looseversion import LooseVersion`.","message":"Direct import from `distutils.version.LooseVersion` will cause `ModuleNotFoundError` in Python 3.12 and later, as `distutils` is removed from the standard library.","severity":"breaking","affected_versions":"Python 3.12+"},{"fix":"Evaluate whether your version comparison needs align with PEP 440 (use `packaging.version.Version`) or if you require the more flexible, `distutils`-style 'loose' comparison (use `looseversion.LooseVersion`).","message":"For comparing versions of Python packages that strictly follow PEP 440, `packaging.version.Version` is generally preferred. `looseversion.LooseVersion` is specifically designed for more heterogeneous or 'anarchic' version schemes that do not conform to PEP 440.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Test `looseversion` behavior with your specific, non-standard version string formats to ensure it meets expectations, especially for complex or highly unconventional patterns.","message":"While `looseversion.LooseVersion` aims for compatibility, some very unusual version strings (e.g., those starting with non-numeric characters in segments) might behave unexpectedly due to its underlying 'loose' parsing logic, which differs significantly from strict semantic versioning. It attempts to split on periods or letter strings and compare numerically/lexically.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}