python
data_error
ai_generated
true
packaging.version.InvalidVersion: Invalid version: '1.0.0-rc.1+build.5.6.7.8.9.10'
ID: python/pip-version-parse-invalid-version
80%Fix Rate
84%Confidence
0Evidence
2024-06-11First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.9 | active | — | — | — |
| 3.10 | active | — | — | — |
| 3.11 | active | — | — | — |
| 3.12 | active | — | — | — |
Root Cause
A package version string does not conform to PEP 440. This often happens with custom-built or vendored packages whose version was set from a git describe or CI variable containing invalid characters.
generic中文
包版本字符串不符合 PEP 440。这通常发生在自定义构建或内置包上,其版本从包含无效字符的 git describe 或 CI 变量设置而来。
Workarounds
-
80% success
from packaging.version import Version, InvalidVersion def normalize(v): try: return str(Version(v)) except InvalidVersion: return v.replace('-rc.', 'rc').replace('+', '.post') print(normalize('1.0.0-rc.1')) # 1.0.0rc1 -
85% success
# in setup.py from setuptools import setup setup(name='mypkg', version='1.0.0rc1') # not 1.0.0-rc.1
Dead Ends
Common approaches that don't work:
-
90% fail
Pre-release flag doesn't relax PEP 440 validation; the version string is still invalid.
-
85% fail
Ignoring installed packages doesn't change version parsing.