{"id":"9750f0fcd7dfb726","repo":"python-poetry/poetry","slug":"invalid-dependency-specification-requirement","errorCode":null,"errorMessage":"Invalid dependency specification: {requirement}","messagePattern":"Invalid dependency specification: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/poetry/utils/dependency_specification.py","lineNumber":96,"sourceCode":"\n        extras = []\n        extras_m = re.search(r\"\\[([\\w\\d,-_ ]+)\\]$\", requirement)\n        if extras_m:\n            extras = [e.strip() for e in extras_m.group(1).split(\",\")]\n            requirement, _ = requirement.split(\"[\")\n\n        specification = (\n            self._parse_url(requirement)\n            or self._parse_path(requirement)\n            or self._parse_simple(requirement)\n        )\n\n        if specification:\n            if extras:\n                specification.setdefault(\"extras\", extras)\n            return specification\n\n        raise ValueError(f\"Invalid dependency specification: {requirement}\")\n\n    def _parse_pep508(self, requirement: str) -> DependencySpec | None:\n        if \" ; \" not in requirement and re.search(r\"@[\\^~!=<>\\d]\", requirement):\n            # this is of the form package@<semver>, do not attempt to parse it\n            return None\n\n        with contextlib.suppress(ValueError):\n            dependency = Dependency.create_from_pep_508(requirement)\n            specification: DependencySpec = {}\n            specification = dependency_to_specification(dependency, specification)\n\n            if specification:\n                specification[\"name\"] = dependency.name\n                return specification\n\n        return None\n\n    def _parse_git_url(self, requirement: str) -> DependencySpec | None:","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/python-poetry/poetry/blob/92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54/src/poetry/utils/dependency_specification.py#L78-L114","documentation":"RequirementsParser.parse raises ValueError when the requirement string cannot be parsed by any strategy — PEP 508, git/url, path, or simple 'name version' form (dependency_specification.py:71-96). It is the catch-all for malformed dependency specifications passed to `poetry add` or the parser API.","triggerScenarios":"Calling RequirementsParser.parse(req) with a malformed string; `poetry add '<bad string>'` where the spec is neither valid PEP 508 nor a Poetry simple/path/url/git form.","commonSituations":"Typos like 'requests >=2.31' with stray spaces inside a constraint, missing quotes around shell-passed specs, unparseable VCS URL, or a path that does not exist.","solutions":["Use valid PEP 508 syntax: `poetry add 'requests>=2.31,<3'` (quote the whole spec in the shell).","For path/url/git deps, use Poetry's table form or `poetry add ./local-pkg` / `git+https://...`.","Remove stray whitespace/punctuation around operators and ensure the package name is valid."],"exampleFix":"// before\npoetry add requests >=2.31        # shell splits into two args -> unparseable\n// after\npoetry add 'requests>=2.31'","handlingStrategy":"validation","validationCode":"from packaging.requirements import InvalidRequirement, Requirement\ntry:\n    Requirement(requirement)\nexcept InvalidRequirement:\n    raise ValueError(f\"Not a valid PEP 508 requirement: {requirement!r}\") from None\nspec = RequirementsParser(artifact_cache=cache).parse(requirement)","typeGuard":null,"tryCatchPattern":"try:\n    spec = parser.parse(requirement)\nexcept ValueError as e:\n    if \"Invalid dependency specification\" in str(e):\n        log.error(\"cannot parse requirement %r; use PEP 508 syntax\", requirement)\n    raise","preventionTips":["Quote requirement strings on the shell to avoid arg splitting.","Prefer the table form in pyproject.toml for complex deps.","Validate requirements with packaging.Requirement before passing to Poetry."],"tags":["dependency","parse-error","pep508","config"],"analyzedSha":"92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54","analyzedAt":"2026-08-04T20:33:34.072Z","schemaVersion":2}