ERROR pip auth_error ai_generated true

错误:命令以退出状态 128 失败:git clone --filter=blob:none '[email protected]:user/private-repo.git' /tmp/pip-install-xxx/package。请检查日志以获取完整命令输出。stderr:[email protected]:权限被拒绝(公钥)。致命错误:无法从远程仓库读取。请确保您拥有正确的访问权限并且仓库存在。

ERROR: Command errored out with exit status 128: git clone --filter=blob:none '[email protected]:user/private-repo.git' /tmp/pip-install-xxx/package. Check the logs for full command output. stderr: [email protected]: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

ID: pip/vcs-git-clone-permission-denied-public-key

其他格式: JSON · Markdown 中文 · English
85%修复率
90%置信度
1证据数
2023-06-10首次发现

版本兼容性

版本状态引入弃用备注
pip 23.0 active
pip 23.2 active
pip 24.0 active
git 2.40 active

根因分析

Pip 尝试通过 SSH 克隆私有 Git 仓库,但 SSH 密钥未配置或未被远程服务器接受,导致公钥认证失败。

English

Pip tries to clone a private Git repository via SSH, but the SSH key is not configured or not accepted by the remote server, causing a public key authentication failure.

generic

官方文档

https://pip.pypa.io/en/stable/topics/vcs-support/

解决方案

  1. 生成 SSH 密钥对并将公钥添加到您的 GitHub 帐户:ssh-keygen -t ed25519 -C '[email protected]';cat ~/.ssh/id_ed25519.pub(复制输出);转到 GitHub 设置 > SSH 和 GPG 密钥 > 新建 SSH 密钥;粘贴并保存。然后重试 pip install。
  2. 在 requirements 文件中使用 HTTPS 而不是 SSH 作为 Git URL:将 git+ssh://[email protected]/user/private-repo.git 替换为 git+https://github.com/user/private-repo.git,并使用个人访问令牌(PAT)进行身份验证:pip install git+https://<PAT>@github.com/user/private-repo.git
  3. 如果仓库是公开的,将 URL 更改为使用无需身份验证的公共 HTTPS 克隆 URL:git+https://github.com/user/public-repo.git

无效尝试

常见但无效的做法:

  1. Using pip install with --no-deps to skip VCS dependencies 95% 失败

    This only avoids the error for the current install but leaves the missing dependency unresolved, causing import errors later.

  2. Adding the SSH key to the ssh-agent with ssh-add without checking the key is correct for the repository 60% 失败

    If the key is not added to the GitHub account or is the wrong key type, authentication still fails.

  3. Setting GIT_SSH_COMMAND='ssh -v' to debug but not fixing the underlying key issue 90% 失败

    Debugging alone does not resolve the authentication failure.