pypa/pip · error · InstallationError

Invalid requirement: {name!r}: {exc}

Error message

Invalid requirement: {name!r}: {exc}

What it means

Raised by parse_req_from_editable() when the project NAME portion of an editable requirement (parsed out of the URL/egg fragment or the `name @ url` form) is not a valid PEP 508 requirement name. After extracting the name at constructors.py:240, get_requirement(name) fails with InvalidRequirement and pip wraps it as an InstallationError.

Source

Thrown at src/pip/_internal/req/constructors.py:242

    return msg


@dataclass(frozen=True)
class RequirementParts:
    requirement: Requirement | None
    link: Link | None
    markers: Marker | None
    extras: set[str]


def parse_req_from_editable(editable_req: str) -> RequirementParts:
    name, url, extras_override = parse_editable(editable_req)

    if name is not None:
        try:
            req: Requirement | None = get_requirement(name)
        except InvalidRequirement as exc:
            raise InstallationError(f"Invalid requirement: {name!r}: {exc}")
    else:
        req = None

    link = Link(url)

    return RequirementParts(req, link, None, extras_override)


# ---- The actual constructors follow ----


def install_req_from_editable(
    editable_req: str,
    comes_from: InstallRequirement | str | None = None,
    *,
    isolated: bool = False,
    hash_options: dict[str, list[str]] | None = None,
    constraint: bool = False,

View on GitHub (pinned to d7d0d0a394)

Solutions

  1. Inspect the name shown in the error and normalize it to a valid PEP 508 name (letters, digits, hyphens, underscores, dots; must not start with a digit).
  2. Re-issue the editable install with the corrected name in either `name @ url` or `#egg=name` form.
  3. Avoid spaces and special characters in the egg fragment.

Example fix

# before
pip install -e "my pkg @ git+https://github.com/org/repo.git"
# after
pip install -e "my-pkg @ git+https://github.com/org/repo.git"
Defensive patterns

Strategy: validation

Validate before calling

from packaging.requirements import Requirement, InvalidRequirement

def validate_editable_name(name: str) -> str:
    try:
        Requirement(name)
    except InvalidRequirement as e:
        raise ValueError(f"Invalid editable requirement name {name!r}: {e}") from e
    return name

Type guard

from packaging.requirements import Requirement, InvalidRequirement

def is_valid_requirement_name(name: str) -> bool:
    try:
        Requirement(name)
        return True
    except InvalidRequirement:
        return False

Try / catch

from pip._internal.exceptions import InstallationError

try:
    parts = parse_req_from_editable(spec)
except InstallationError as e:
    if "Invalid requirement" in str(e):
        # log and surface a user-friendly message
        ...
    raise

Prevention

When it happens

Trigger: An editable spec where the inferred or supplied name contains illegal characters, e.g. `pip install -e "my pkg @ git+https://..."` (space in name), a name with leading digits, or a name fragment with invalid PEP 508 syntax. The name is parsed independently of the URL.

Common situations: Typos in the #egg= fragment. Names containing hyphens mixed with uppercase mismatches. Copy-pasting a display name rather than the normalized distribution name.

Related errors


AI-assisted analysis of pypa/pip@d7d0d0a394 (2026-08-04). Data as JSON: /data/errors/c2475e801e28ef98.json. Report an issue: GitHub.