pip install -e "private_repo" results in error, whereas git clone "private_repo" executes OK

Viewed 310

I have a private git repository on Gitea. I have set up the deploy key there for my server and on the server I have the relevant private key in C:\Users\harry\.ssh\id_ed25519

When I try to directly git clone the repo, it works OK:

(venv) harry@DESKTOP-4NS8B70 d:\>git clone "ssh://git@git.myserver.com/my_username/my_package.git" my_package    
Cloning into 'my_package'...
Enter passphrase for key '/c/Users/harry/.ssh/id_ed25519': 
remote: Enumerating objects: 52, done.
remote: Counting objects: 100% (52/52), done.
Receiving objects: 100% (52/52), 10.18 KiB | 5.09 MiB/s, done.
Resolving deltas:  95% (20/21)00% (45/45), done.
remote: Total 52 (delta 21), reused 0 (delta 0)
Resolving deltas: 100% (21/21), done.

So far, so good! However, when I try to install the very same package by pip install -e "git+ssh://git@git.myserver.com/my_username/my_package.git#egg=my_package" it results in an error:

(venv) harry@DESKTOP-4NS8B70 d:\>pip install -e "git+ssh://git@git.myserver.com/my_username/my_package.git#egg=my_package"
Obtaining my_package from git+ssh://****@git.myserver.com/my_username/my_package.git#egg=my_package
  Cloning ssh://****@git.myserver.com/my_username/my_package.git to d:\my_app\venv\src\my-package
  Running command git clone -q 'ssh://****@git.myserver.com/my_username/my_package.git' 'd:\my_app\venv\src\my-package'
  git@git.myserver.com: Permission denied (publickey).
  fatal: Could not read from remote repository.

  Please make sure you have the correct access rights
  and the repository exists.
WARNING: Discarding git+ssh://****@git.myserver.com/my_username/my_package.git#egg=my_package. Command errored out with exit status 128: git clone -q 'ssh://****@git.myserver.com/my_username/my_package.git' 'd:\my_app\venv\src\my-package' Check the logs for full command output.

Of course, the same thing happens when I try to pip install -r requirements.txt with the following entry

-e "git+ssh://git@git.myserver.com/my_username/my_package.git#egg=my_package"

My first thought is that the issue happens, because it somehow does not ask to Enter passphrase for key, but I have no idea why! Any ideas what else could have gone wrong?

1 Answers

As commented, and described in Pip Installing a Package From a Private Repository from Fernando Freitas Alves, adding an ssh agent will allow your pip command to complete:

cd ~/.ssh
ssh-keygen -t rsa -b 4096 -C "dev@email.com"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa

The alternative is to use an HTTPS URL:

git config --global url.https://github.com/.insteadOf git@github.com:

The same pip command would automatically used an HTTPS URL instead of the SSH one, assuming you have a credential manager caching your credentials.

Related