How to Use Pip to Install a Package from a Private Github Repository

Is it possible to use pip to install a package from a private GitHub repository?

You can use the git+ssh URI scheme, but you must set a username. Notice the git@ part in the URI:

pip install git+ssh://git@github.com/echweb/echweb-utils.git

Also read about deploy keys.

PS: In my installation, the "git+ssh" URI scheme works only with "editable" requirements:

pip install -e URI#egg=EggName

Remember: Change the : character that git remote -v prints to a / character before using the remote's address in the pip command:

$ git remote -v
origin git@github.com:echweb/echweb-utils.git (fetch)
# ^ change this to a '/' character

If you forget, you will get this error:

ssh: Could not resolve hostname github.com:echweb:
nodename nor servname provided, or not known

Pip install a whl on a private github repo?

You should be able to do

pip install https://{token}@raw.githubusercontent.com/{user}/{repo}/master/{name.whl}

pip install package from private github repo with deploy key in docker

git@github.com:organization/my-package.git is a valid SSH URL.
ssh://git@github.com:organization/my-package.git is not.
ssh://git@github.com/organization/my-package.git would be.

As in here, you can add GIT_SSH_COMMAND='ssh -v' pip install ... to see exactly what is going on.

You might need:

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

The OP arabinelli reports in the comments having to use the following line in requirements.txt:

git+ssh://git@github.com/my-organization/my-repo-name@master#egg=my_package_dir

Aug. 2022, Jako adds in the comments:

This worked for me with a private BitBucket repository:

git+ssh://git@bitbucket.org/my-organization/my-repo-name@master#egg=my_project&subdirectory=subdir1

                                      ^^^^^^^

I had to specify the subdirectory 'subdir1'

Simple way to pip install a private Github repo?

Really, if you want a secure and easy way to do it, SSH is the way to go (as stated by Romeo). While daunting at first due to the sheer amount of information, implementing it is actually super easy, and actually less complex than other alternatives. This video walks through it step by step:

https://www.youtube.com/watch?v=nQDFBd5NFA8

The only thing that's the least bit tricky, if you're doing this on some sort of ec2 instance, you might need to use a text editor like nano to view the public key so you can copy it. just do

nano ~/.ssh/id_rsa.pub

then, because its long, you can enable code wrapping by

press esc, release esc, shift+4

that will allow you to, view the whole ssh public key so you can easily copy it on the machine where you're setting everything up

Installing with pip requirements.txt from a private git repo using ssh OR https

I'm almost certain this is impossible for pip because Git doesn't, in general, provide a way to do this.

Just because GitHub provides both HTTPS and SSH remotes for the same repository doesn't mean that all providers do. Even when a hosting provider provides both, they may not necessarily be under the same location relative to the root for each protocol.

Moreover, Git doesn't do automatic fallbacks between protocols in case of failure because different protocols are implemented in completely different code (and sometimes, in different binaries) and because it's not clear in what case a fallback should occur. For example, should Git fall back if authentication fails? Should it fall back if there are no authentication credentials but some are required?

In general, if you're providing a public repo (which is not the case here), yo should always use HTTPS for GitHub, because that's anonymous, which means it will just work. For a private repository, I'd use whatever you think everyone is most likely to have. For example, if you know every engineer will have an SSH key for access to certain systems, that can be a good choice, but if you know that your development environment setup script uses HTTPS, then use that.

Note that people can rewrite the URLs in their local instances using url.*.insteadOf, which can rewrite one type of URL into the other automatically. I happen to use this to use an SSH key for all my access because my organization requires time-limited HTTPS tokens and I don't want to deal with rotation.

pip install a package from a private repo but dependencies from PyPi behind a proxy

Use the no_proxy environment variable (comma-separated list of host names which shouldn't go through any proxy) to omit internal hosts such as my-organization.



Related Topics



Leave a reply



Submit