使用pip通过SSH安装Azure DevOps私有包报错,请求问题分析
使用pip通过SSH安装Azure DevOps私有包的错误分析
已知正常场景
- 可通过
git clone命令,使用SSH或HTTPS协议成功克隆目标仓库 - 使用
pip install "git+https://<repository_https_url>"命令可成功安装包
错误1:使用pip install "git+ssh://<repository_ssh_url>"失败
错误信息
pip install "git+ssh://<repository_ssh_url>" Collecting git+ssh://****@ssh.dev.azure.com:v3/***/LindeUtils Cloning ssh://****@ssh.dev.azure.com:v3/***/LindeUtils to c:\users\****\temp\pip-req-build-_o7f2wcb Running command git clone --filter=blob:none --quiet 'ssh://****@ssh.dev.azure.com:v3/***/LindeUtils' 'C:\Users\****\Temp\pip-req-build-_o7f2wcb' ssh: Could not resolve hostname ssh.dev.azure.com:v3: Name or service not known fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. error: subprocess-exited-with-error
原因分析
SSH URL格式错误。在ssh://协议的URL中,冒号:用于指定端口号,但你提供的URL里将Azure DevOps仓库路径的/v3写成了:v3,导致SSH客户端把ssh.dev.azure.com:v3当作完整的主机名去解析,而实际不存在这个主机,因此解析失败。
Azure DevOps正确的SSH格式应为:
git+ssh://git@ssh.dev.azure.com/v3/{组织名}/{项目名}/{仓库名}
错误2:使用pip install "git+ssh://<repository_https_url>"失败
错误信息
pip install "git+ssh://<repository_https_url>" Collecting git+ssh://****@dev.azure.com/***/LindeUtils Cloning ssh://****@dev.azure.com/***/LindeUtils to c:\users\****\temp\pip-req-build-a_xjd47o Running command git clone --filter=blob:none --quiet 'ssh://****@dev.azure.com/***/LindeUtils' 'C:\Users\****\Temp\pip-req-build-a_xjd47o' ssh: connect to host dev.azure.com port 22: Network is unreachable fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. error: subprocess-exited-with-error
原因分析
- 主机与端口不匹配:Azure DevOps的SSH服务部署在
ssh.dev.azure.com而非dev.azure.com,dev.azure.com默认不监听SSH的22端口,因此无法建立连接。 - URL路径格式错误:HTTPS协议的仓库路径与SSH协议的路径结构不同,直接替换协议前缀会导致路径不匹配,无法定位到正确的仓库。
解决建议
使用Azure DevOps官方提供的正确SSH仓库URL,格式如下:
pip install "git+ssh://git@ssh.dev.azure.com/v3/你的组织名/你的项目名/你的仓库名"
内容的提问来源于stack exchange,提问作者DragonFang
相关产品推荐
相关产品推荐

