pypa/pip · error · InvalidEggFragment

invalid-egg-fragment

invalid-egg-fragment

Error message

The '{fragment}' egg fragment is invalid

What it means

Error "The '{fragment}' egg fragment is invalid" thrown in pypa/pip.

Source

Thrown at src/pip/_internal/models/link.py:526

        return urllib.parse.urlunsplit((scheme, netloc, path, query, ""))

    _egg_fragment_re = re.compile(r"[#&]egg=([^&]*)")

    # Per PEP 508.
    _project_name_re = re.compile(
        r"^([A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9])$", re.IGNORECASE
    )

    def _egg_fragment(self) -> str | None:
        match = self._egg_fragment_re.search(self._url)
        if not match:
            return None

        # An egg fragment looks like a PEP 508 project name, along with
        # an optional extras specifier. Anything else is invalid.
        project_name = match.group(1)
        if not self._project_name_re.match(project_name):
            raise InvalidEggFragment(self, project_name)

        return project_name

    _subdirectory_fragment_re = re.compile(r"[#&]subdirectory=([^&]*)")

    @property
    def subdirectory_fragment(self) -> str | None:
        match = self._subdirectory_fragment_re.search(self._url)
        if not match:
            return None
        return match.group(1)

    def metadata_link(self) -> Link | None:
        """Return a link to the associated core metadata file (if any)."""
        if self.metadata_file_data is None:
            return None
        metadata_url = f"{self.url_without_fragment}.metadata"
        if self.metadata_file_data.hashes is None:

View on GitHub (pinned to d7d0d0a394)

When it happens

Trigger: Thrown at src/pip/_internal/models/link.py:526 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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