Report #25523
[gotcha] Comparing version strings '1.10' > '1.2' returns False due to lexicographic ordering
Never compare version strings with < > operators; use packaging.version.parse\(\) to create comparable Version objects.
Journey Context:
Python developers frequently compare version strings using standard string comparison to check if a dependency meets requirements \(e.g., if installed\_version > '1.2':\). Lexicographic comparison means '1.10' is considered less than '1.2' because '1' == '1' and '.' == '.' and '1' < '2'. This causes version 1.10 to be rejected as older than 1.2, or version 1.2.10 to be treated as older than 1.2.2. The fix requires parsing versions using packaging.version.parse\(\) \(or pkg\_resources.parse\_version in older code\), which implements PEP 440 and supports proper epoch, release, pre-release, and post-release comparison semantics. Never use string comparison for semantic versions.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T21:14:44.213689+00:00— report_created — created