# packaging.version.InvalidVersion: Invalid version: '1.0.0-beta.1+build_42!'

- **ID:** `python/packaging-version-invalid-pep440`
- **Domain:** python
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A version string does not conform to PEP 440. Characters like '!' or malformed pre-release separators ('-beta' vs 'b') are rejected by packaging.version.Version.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.8+ | active | — | — |

## Workarounds

1. **** (85% success)
   ```
   from packaging.version import Version, InvalidVersion
raw = '1.0.0-beta.1+build_42!'.rstrip('!')
v = Version(raw.replace('-beta', 'b'))
print(v)  # 1.0.0b1+build.42
   ```
2. **** (90% success)
   ```
   # pyproject.toml
[project]
version = "1.0.0b1"  # PEP 440 pre-release form
# or use dynamic versioning from git tags via setuptools-scm
   ```

## Dead Ends

- **** — LegacyVersion was removed in packaging 22+; importing it raises ImportError. Even when available, comparisons are unreliable. (90% fail)
- **** — Produces a different version (e.g. '100beta1build42') that no longer reflects intent and may collide with real releases. (80% fail)
