具有私人要求的 pip 安装失败

pip install with private requirements fails

我有以下 requirements.txt 文件:

git+ssh://git@bitbucket.org/.../...git@4.19.0#subdirectory=py 
git+ssh://git@bitbucket.org/.../...git@c99b7f6f372c92832eecfb90663833ef1fd3dc62
git+ssh://git@bitbucket.org/.../...git@45d2999ce5f6eba5dd728414073a10d1c50616a2
git+ssh://git@bitbucket.org/.../....git@1ba2781cd2beae6d23218565c395b633b0eb5328

然而,当我尝试安装它时,它失败了:

$ pip install -r requirements.txt
Collecting git+ssh://****@bitbucket.org/.../...git@4.19.0#subdirectory=py (from -r requirements.txt (line 8))
Cloning ssh://****@bitbucket.org/.../...git (to revision 4.19.0) to c:\users\...\appdata\local\temp\pip-req-build-t9_wrhxh
ERROR: Command errored out with exit status 128: git clone -q 'ssh://****@bitbucket.org/.../...git' 'C:\Users\...\AppData\Local\Temp\pip-req-build-t9_wrhxh' Check the logs for full command output.

其他同事能够安装要求...这是什么原因?如果我在相同的地方克隆,如该错误消息所示,它工作正常:

$ git clone ssh://git@bitbucket.org/.../....git
Cloning into '...'... 
Enter passphrase for key '/c/Users/.../.ssh/id_rsa': 
remote: Counting objects: 2053, done. 
remote: Compressing objects: 100% (1648/1648), done. 
remote: Total 2053 (delta 1279), reused 385 (delta 200) 
Receiving objects: 100% (2053/2053), 1.88 MiB | 611.00 KiB/s, done. Resolving deltas: 100% (1279/1279), done.
$ pip install -r requirements.txt
...
ERROR: Command errored out with exit status 128: 
   git clone -q 'ssh://****@bitbucket.org/.../...git' 'C:\Users\...\AppData\Local\Temp\pip-req-build-t9_wrhxh'
   Check the logs for full command output.

运行 pip install 中的这一行包括正在执行的命令。这只是正常的 git clone 写入失败的临时目录(可以忽略)。 -q(安静)标志抑制了一些输出。

$ git clone ssh://git@bitbucket.org/.../....git
...
Enter passphrase for key '/c/Users/.../.ssh/id_rsa': 

克隆中的这一行直接表明,虽然克隆成功,但用于与 bitbucket 进行身份验证的密钥具有密码。在交互式进程中克隆时,git 能够提示它 - 但在 none 交互式进程(例如 pip)中并非如此。

解决方案

有多种方法可以解决这个问题,但最简单的方法是:

  • 创建一个新的 ssh 密钥对没有密码
  • 将此密钥添加到您的 bitbucket 帐户
  • 配置 ssh 以将此密钥用于 bitbucket.org
Host bitbucket.org
   IdentityFile ~/.ssh/no_passphrase.id_rsa
  • 成功