pypa/pip · error · RemoteNotValidError

{url}

Error message

{url}

What it means

Raised by Git._git_remote_to_pip_url() (as a RemoteNotValidError) when a git remote URL does not match any of the three recognized forms: a fully-qualified URL (scheme://), an existing local bare-repo path, or SCP shorthand (user@host:path). The URL cannot be converted to a pip-installable requirement string.

Source

Thrown at src/pip/_internal/vcs/git.py:448

        Form 1 is output as-is. Form 2 must be converted to URI and form 3 must
        be converted to form 1.

        See the corresponding test test_git_remote_url_to_pip() for examples of
        sample inputs/outputs.
        """
        if re.match(r"\w+://", url):
            # This is already valid. Pass it though as-is.
            return url
        if os.path.exists(url):
            # A local bare remote (git clone --mirror).
            # Needs a file:// prefix.
            return pathlib.Path(url).as_uri()
        scp_match = SCP_REGEX.match(url)
        if scp_match:
            # Add an ssh:// prefix and replace the ':' with a '/'.
            return scp_match.expand(r"ssh://\1\2/\3")
        # Otherwise, bail out.
        raise RemoteNotValidError(url)

    @classmethod
    def has_commit(cls, location: str, rev: str) -> bool:
        """
        Check if rev is a commit that is available in the local repository.
        """
        try:
            cls.run_command(
                ["rev-parse", "-q", "--verify", rev + "^{commit}"],
                cwd=location,
                log_failed_cmd=False,
            )
        except InstallationError:
            return False
        else:
            return True

    @classmethod

View on GitHub (pinned to f399c37189)

Solutions

  1. Check the remote URL: 'git -C <repo> config --get remote.origin.url'
  2. Fix the remote URL to a recognized form (https://, ssh://, git@host:path, or an absolute local path)
  3. Re-clone the repository from a valid remote URL
  4. If installing from a local clone, use 'pip install <path>' instead of a git+ URL

Example fix

// before
# remote.origin.url is a malformed value like 'repo'
git -C ./myrepo config --get remote.origin.url  # => 'repo'
pip install ./myrepo
// after
# fix the remote to a valid URL
git -C ./myrepo remote set-url origin https://example.com/repo.git
pip install ./myrepo
Defensive patterns

Strategy: validation

Validate before calling

import re, os

SCP_RE = re.compile(r'^(\w+@)?([^/:]+):(\w[^:]*)$')

def git_remote_is_valid(url: str) -> bool:
    if re.match(r'\w+://', url):
        return True
    if os.path.exists(url):
        return True
    if SCP_RE.match(url):
        return True
    return False

# before relying on a git remote
if not git_remote_is_valid(remote_url):
    raise ValueError(f'git remote URL is not valid: {remote_url}')

Type guard

import re, os

def is_valid_git_url(url: str) -> bool:
    return bool(re.match(r'\w+://', url)) or os.path.exists(url) or bool(re.match(r'^(\w+@)?([^/:]+):(\w[^:]*)$', url))

Try / catch

from pip._internal.vcs.versioncontrol import RemoteNotValidError

try:
    url = Git.get_remote_url(location)
except RemoteNotValidError as e:
    raise ConfigError(f'fix the git remote URL: {e.url}')

Prevention

When it happens

Trigger: Calling get_remote_url() on a git checkout whose 'remote.origin.url' config value is none of: a URL with a scheme, an existing local path, or SCP shorthand. The error is raised at line 448 via RemoteNotValidError(url).

Common situations: A git remote configured with a malformed or non-standard URL. A remote using a protocol pip does not recognize. A manually edited .git/config with a broken remote URL. A remote URL that is a relative path rather than absolute.

Related errors


AI-assisted analysis of pypa/pip@f399c37189 (2026-08-08). Data as JSON: /api/errors/4b7b789cc5942f74. Report an issue: GitHub.