Registry / serialization / looseversion

looseversion

JSON →
library1.3.0pypypi✓ verified 23d ago

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.

pip install looseversion
INSTALL
IMPORT
SIG · LOOSEVERSION
L
looseversion
serializationpythonv1.3.0
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.3.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

LooseVersion
from looseversion import LooseVersion
from distutils.version import LooseVersion
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.

Demonstrates basic version object creation and comparison, including comparison with a string literal.

from looseversion import LooseVersion v1 = LooseVersion("1.0.0") v2 = LooseVersion("2.0.0") print(f"'{v1}' < '{v2}' is {v1 < v2}") print(f"'{v1}' < '2' is {v1 < '2'}")
Debug
Known issues
breakingDirect import from `distutils.version.LooseVersion` will cause `ModuleNotFoundError` in Python 3.12 and later, as `distutils` is removed from the standard library.
fix
Change import statements from `from distutils.version import LooseVersion` to `from looseversion import LooseVersion`.
affects: Python 3.12+
gotchaFor 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.
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`).
affects: All versions
gotchaWhile `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.
fix
Test `looseversion` behavior with your specific, non-standard version string formats to ensure it meets expectations, especially for complex or highly unconventional patterns.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'distutils'
The `distutils` package, which historically contained `LooseVersion`, has been deprecated and removed in Python 3.12 and later versions.
fix
Update your import statement from `from distutils.version import LooseVersion` to `from looseversion import LooseVersion`.
AttributeError: module 'distutils' has no attribute 'version'
This error occurs when code attempts to access `distutils.version.LooseVersion`, but the `distutils` module or its `version` attribute is no longer directly available or has moved within `setuptools` in newer Python environments.
fix
Change the import statement to `from looseversion import LooseVersion`.
AttributeError: 'LooseVersion' object has no attribute 'version'
This typically happens when an invalid or `None` value is passed to the `LooseVersion` constructor, or when a comparison is attempted between a `LooseVersion` object and an incompatible type, leading to an attempt to access a non-existent `.version` attribute on the `LooseVersion` instance itself.
fix
Ensure that a valid version string is always passed to the `LooseVersion()` constructor, and that comparisons are made between properly initialized `LooseVersion` objects or compatible types.
TypeError: '<' not supported between instances of 'str' and 'int'
This error arises when `LooseVersion` attempts to compare components of version strings that are of fundamentally different and unorderable types (e.g., a string like 'alpha' and an integer like '1') within its comparison logic.
fix
While `looseversion` is designed for flexible versioning, review the version strings for highly heterogeneous segments that might not have a clear comparative order. Consider normalizing such segments or ensuring consistency in type for comparable parts.
Upgrade
Version history
1.3.0latest on PyPI · released Jul 5, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
Resources
looseversion — pip install looseversion · libregistry