{"record":{"id":"7d4f7b6c5e466aad","repo":"pypa/pip","slug":"unnamed-requirements-are-not-allowed-as-constraint","errorCode":null,"errorMessage":"Unnamed requirements are not allowed as constraints","messagePattern":"Unnamed requirements are not allowed as constraints","errorType":"exception","errorClass":"InstallationError","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/resolution/resolvelib/factory.py","lineNumber":553,"sourceCode":"            else:\n                # require the base from the link\n                yield self.make_requirement_from_candidate(cand)\n                if ireq.extras:\n                    # require the extras on top of the base candidate\n                    yield self.make_requirement_from_candidate(\n                        self._make_extras_candidate(cand, frozenset(ireq.extras))\n                    )\n\n    def collect_root_requirements(\n        self, root_ireqs: list[InstallRequirement]\n    ) -> CollectedRootRequirements:\n        collected = CollectedRootRequirements([], {}, {})\n        for i, ireq in enumerate(root_ireqs):\n            if ireq.constraint:\n                # Ensure we only accept valid constraints\n                problem = check_invalid_constraint_type(ireq)\n                if problem:\n                    raise InstallationError(problem)\n                if not ireq.match_markers():\n                    continue\n                assert ireq.name, \"Constraint must be named\"\n                name = canonicalize_name(ireq.name)\n                if name in collected.constraints:\n                    collected.constraints[name] &= ireq\n                else:\n                    collected.constraints[name] = Constraint.from_ireq(ireq)\n            else:\n                reqs = list(\n                    self._make_requirements_from_install_req(\n                        ireq,\n                        requested_extras=(),\n                    )\n                )\n                if not reqs:\n                    continue\n                template = reqs[0]","sourceCodeStart":535,"sourceCodeEnd":571,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/resolution/resolvelib/factory.py#L535-L571","documentation":"check_invalid_constraint_type (req_install.py:811-812) and collect_root_requirements (factory.py:551-553) reject constraint entries that have no package name (Unnamed requirements). Constraints must be a package name plus an optional version specifier; bare URLs or paths without a name are not allowed because the new resolver cannot key them.","triggerScenarios":"A constraints file (-c constraints.txt) contains an unnamed requirement such as a bare URL or a local path without a name.","commonSituations":"Putting a bare URL or ./local/pkg directly in a constraints file instead of the requirements file.","solutions":["Give the constraint a name using PEP 508 direct reference form: name @ url.","Move unnamed path/url requirements out of the constraints file into the main requirements file.","Express the constraint as pkg==<version> only."],"exampleFix":"# before (constraints.txt)\ngit+https://github.com/org/pkg.git\n# after\npkg @ git+https://github.com/org/pkg.git","handlingStrategy":"validation","validationCode":"# Validate a constraints file has no unnamed requirements.\nimport sys\nfor line in open(\"constraints.txt\"):\n    s = line.strip()\n    if not s or s.startswith(\"#\"):\n        continue\n    # unnamed if it starts with a path/url indicator and has no 'name @'\n    if (s.startswith((\"http\", \"git+\", \"hg+\", \"svn+\", \"./\", \"/\", \"..\"))) and \"@\" not in s.split()[0]:\n        print(f\"Unnamed constraint not allowed: {s}\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Constraints files should only contain 'name==version' style lines.","Use 'name @ url' direct-reference form if you must reference a URL.","Keep path/url installs in the requirements file, not constraints."],"tags":["constraints","unnamed-requirement"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}