{"record":{"id":"14335efc1ae48df2","repo":"pypa/pip","slug":"editable-requirements-are-not-allowed-as-constrain","errorCode":null,"errorMessage":"Editable requirements are not allowed as constraints","messagePattern":"Editable requirements are not allowed as constraints","errorType":"validation","errorClass":"InstallationError","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/req/constructors.py","lineNumber":265,"sourceCode":"\n    return RequirementParts(req, link, None, extras_override)\n\n\n# ---- The actual constructors follow ----\n\n\ndef install_req_from_editable(\n    editable_req: str,\n    comes_from: InstallRequirement | str | None = None,\n    *,\n    isolated: bool = False,\n    hash_options: dict[str, list[str]] | None = None,\n    constraint: bool = False,\n    user_supplied: bool = False,\n    config_settings: dict[str, str | list[str]] | None = None,\n) -> InstallRequirement:\n    if constraint:\n        raise InstallationError(\"Editable requirements are not allowed as constraints\")\n\n    parts = parse_req_from_editable(editable_req)\n    return InstallRequirement(\n        parts.requirement,\n        comes_from=comes_from,\n        user_supplied=user_supplied,\n        editable=True,\n        link=parts.link,\n        constraint=constraint,\n        isolated=isolated,\n        hash_options=hash_options,\n        config_settings=config_settings,\n        extras=parts.extras,\n    )\n\n\ndef _looks_like_path(name: str) -> bool:\n    \"\"\"Checks whether the string \"looks like\" a path on the filesystem.","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/req/constructors.py#L247-L283","documentation":"pip raises this when an editable requirement (-e) is combined with the constraint flag. Constraint files are meant to restrict versions without installing; editable installs are development installs that are always installed. The two concepts are mutually exclusive, so pip refuses the combination at the top of install_req_from_editable().","triggerScenarios":"Calling install_req_from_editable(editable_req, constraint=True), or running pip with a constraint file (-c constraints.txt) that contains a line starting with -e (editable). Also triggered when install_req_from_parsed_requirement forwards parsed_req.constraint=True into the editable path.","commonSituations":"A constraints.txt file mistakenly contains '-e ./myproject' lines instead of plain version pins. Mixing editable development installs with a constraint file in CI. Refactoring a requirements file into a constraint file without removing -e lines.","solutions":["Remove any -e lines from your constraint file; constraint files should only contain version specifiers like 'package>=1.0,<2.0'","If you need an editable install, put it in a requirements file (-r) or on the command line, not in a constraint file (-c)","Separate editable dev dependencies into their own requirements file and only use plain name==version pins in constraint files"],"exampleFix":"# before — constraints.txt contains:\n#   -e ./myproject\n\n# after — constraints.txt contains:\n#   myproject","handlingStrategy":"validation","validationCode":"# Before passing an editable requirement, ensure it is not marked as a constraint\nif constraint and editable_req.startswith(\"-e\") or is_editable_line:\n    raise ValueError(\"Editable requirements cannot be used as constraints\")\n\n# Or simply: never call install_req_from_editable(..., constraint=True)","typeGuard":"def is_safe_constraint_line(line: str) -> bool:\n    \"\"\"Returns False if the line would trigger the editable-as-constraint error.\"\"\"\n    stripped = line.strip()\n    return not (stripped.startswith(\"-e \") or stripped.startswith(\"--editable\"))","tryCatchPattern":"from pip._internal.exceptions import InstallationError\n\ntry:\n    ireq = install_req_from_editable(req, constraint=False)\nexcept InstallationError as e:\n    if \"not allowed as constraints\" in str(e):\n        # retry without constraint flag, or move to a requirements file\n        ireq = install_req_from_editable(req, constraint=False)\n    else:\n        raise","preventionTips":["Never put -e lines in a constraint file (-c); use them only in requirements files (-r)","When refactoring a requirements file into a constraint file, strip all -e lines first","Validate constraint files with a script that checks no line starts with -e or --editable"],"tags":["pip","editable","constraint","requirements","installation"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}