{"record":{"id":"d38a65d45be35425","repo":"pypa/pip","slug":"invalid-pyproject-build-system-requires","errorCode":"invalid-pyproject-build-system-requires","errorMessage":"Can not process {package}","messagePattern":"Can not process (.+?)","errorType":"validation","errorClass":"InvalidPyProjectBuildRequires","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/pyproject.py","lineNumber":90,"sourceCode":"        # traditional direct setup.py execution, and require wheel and\n        # a version of setuptools that supports that backend.\n\n        build_system = {\n            \"requires\": [\"setuptools>=40.8.0\"],\n            \"build-backend\": \"setuptools.build_meta:__legacy__\",\n        }\n\n    # Ensure that the build-system section in pyproject.toml conforms\n    # to PEP 518.\n\n    # Specifying the build-system table but not the requires key is invalid\n    if \"requires\" not in build_system:\n        raise MissingPyProjectBuildRequires(package=req_name)\n\n    # Error out if requires is not a list of strings\n    requires = build_system[\"requires\"]\n    if not _is_list_of_str(requires):\n        raise InvalidPyProjectBuildRequires(\n            package=req_name,\n            reason=\"It is not a list of strings.\",\n        )\n\n    # Each requirement must be valid as per PEP 508\n    for requirement in requires:\n        try:\n            get_requirement(requirement)\n        except InvalidRequirement as error:\n            raise InvalidPyProjectBuildRequires(\n                package=req_name,\n                reason=f\"It contains an invalid requirement: {requirement!r}\",\n            ) from error\n\n    backend = build_system.get(\"build-backend\")\n    backend_path = build_system.get(\"backend-path\", [])\n    check: list[str] = []\n    if backend is None:","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/pyproject.py#L72-L108","documentation":"Raised by load_pyproject_toml (pyproject.py:89) as InvalidPyProjectBuildRequires (code: invalid-pyproject-build-system-requires) when [build-system].requires exists but is not a list of strings. PEP 518 requires requires to be a list of (PEP 508) requirement strings; any other type is rejected via the _is_list_of_str check.","triggerScenarios":"[build-system].requires is set to a non-list (a string, dict, number) or a list containing non-string elements. e.g. requires = \"setuptools\" (a bare string instead of a list) or requires = [42].","commonSituations":"Author wrote a single string instead of a one-element list; YAML->TOML conversion mistakes; copy-paste from docs that dropped the brackets.","solutions":["Make requires a list of strings: requires = [\"setuptools>=61\"].","Re-run after fixing the TOML; pip will re-parse on next build.","Validate with 'tomllib.loads' / a TOML schema linter."],"exampleFix":"# before (pyproject.toml)\n[build-system]\nrequires = \"setuptools>=61\"\n# after\n[build-system]\nrequires = [\"setuptools>=61\"]","handlingStrategy":"validation","validationCode":"from pip._internal.utils.compat import tomllib\n\ndef requires_is_list_of_str(pyproject_path: str) -> tuple[bool, str | None]:\n    with open(pyproject_path, 'rb') as f:\n        bs = tomllib.load(f).get('build-system')\n    if bs is None:\n        return True, None\n    req = bs.get('requires')\n    ok = isinstance(req, list) and all(isinstance(x, str) for x in req)\n    return ok, None if ok else 'requires must be a list of strings'","typeGuard":"from typing import Any\n\ndef is_list_of_str(obj: Any) -> bool:\n    return isinstance(obj, list) and all(isinstance(x, str) for x in obj)","tryCatchPattern":"from subprocess import run, CalledProcessError\ntry:\n    run([\"pip\", \"install\", target], check=True)\nexcept CalledProcessError:\n    # Fix requires to a list of strings, then rebuild.\n    run([\"python\", \"-m\", \"build\", target], check=True)","preventionTips":["Always write requires as a list of strings, even for a single dependency.","Validate pyproject.toml structure in CI with a TOML/PEP 518 checker.","Use a project template that emits correct build-system tables."],"tags":["pyproject","pep518","build-system","requires","config","validation","pip"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}