pypa/pip · error · InstallationError
Error parsing
Error message
Error parsing {path}: {e} What it means
The pyproject.toml file exists but contains invalid TOML syntax. The _load_pyproject helper caught a tomllib.TOMLDecodeError (e.g. duplicate keys, unclosed brackets, invalid escape sequences) and wrapped it in an InstallationError.
Solutions
- Validate the TOML: 'python -c "import tomllib; tomllib.load(open('pyproject.toml','rb'))"' to get a line-number error
- Check for merge-conflict markers and remove them
- Look for duplicate keys or table headers
- Use a TOML linter or IDE with TOML validation
Defensive patterns
Strategy: validation
Validate before calling
from pip._internal.utils.compat import tomllib
def validate_pyproject_toml(path: str) -> bool:
try:
with open(path, "rb") as fp:
tomllib.load(fp)
return True
except tomllib.TOMLDecodeError:
return False
if not validate_pyproject_toml("pyproject.toml"):
print("pyproject.toml has TOML syntax errors") Type guard
from pip._internal.utils.compat import tomllib
def is_valid_toml_file(path: str) -> bool:
"""Type guard: True if the file parses as valid TOML."""
try:
with open(path, "rb") as fp:
tomllib.load(fp)
return True
except (tomllib.TOMLDecodeError, OSError):
return False Try / catch
from pip._internal.exceptions import InstallationError
from pip._internal.req.req_dependency_group import parse_dependency_groups
try:
reqs = parse_dependency_groups([("pyproject.toml", "dev")])
except InstallationError as e:
if "Error parsing" in str(e):
print("Fix TOML syntax in pyproject.toml")
else:
raise Prevention
- Validate pyproject.toml with tomllib.load() before running pip --group
- Use a TOML linter or IDE with TOML validation
- Check for merge-conflict markers after resolving git conflicts
When it happens
Trigger: pyproject.toml has a syntax error such as a duplicate table header, an unterminated string, or an invalid value. tomllib.load() raises TOMLDecodeError.
Common situations: Hand-editing pyproject.toml and introducing a typo. Merge conflicts leaving conflict markers (<<<<<<<) in the file. Tooling that generates malformed TOML. Missing quotes around values.
Related errors
- [dependency-groups] resolution failed for
- [dependency-groups] table was malformed in
- [dependency-groups] table was missing from
- Error reading
- Failed to parse TOML in
AI-assisted analysis of pypa/pip@f399c37189 (2026-08-08).
Data as JSON: /api/errors/54109bd34aeab893.
Report an issue: GitHub.
Appendix: source
Thrown at src/pip/_internal/req/req_dependency_group.py:84
f"[dependency-groups] data was invalid in {path}: {'; '.join(messages)}"
) from eg
return resolvers
def _load_pyproject(path: str) -> dict[str, Any]:
"""
This helper loads a pyproject.toml as TOML.
It raises an InstallationError if the operation fails.
"""
try:
with open(path, "rb") as fp:
return tomllib.load(fp)
except FileNotFoundError:
raise InstallationError(f"{path} not found. Cannot resolve '--group' option.")
except tomllib.TOMLDecodeError as e:
raise InstallationError(f"Error parsing {path}: {e}") from e
except OSError as e:
raise InstallationError(f"Error reading {path}: {e}") from e
View on GitHub (pinned to f399c37189)