The Python Oracle

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

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Life in a Drop

--

Chapters
00:00 Question
01:31 Accepted answer (Score 552)
02:26 Answer 2 (Score 95)
02:51 Answer 3 (Score 55)
03:15 Answer 4 (Score 41)
03:32 Thank you

--

Full question
https://stackoverflow.com/questions/4830...

Accepted answer links:
[deploy keys]: http://help.github.com/deploy-keys/

Answer 3 links:
[Django]: http://en.wikipedia.org/wiki/Django_%28w...

Answer 4 links:
[Bitbucket]: http://en.wikipedia.org/wiki/Bitbucket

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #git #github #pip

#avk47



ACCEPTED ANSWER

Score 620


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



ANSWER 2

Score 101


As an additional technique, if you have the private repository cloned locally, you can do:

pip install git+file://c:/repo/directory

More modernly, you can just do this (and the -e will mean you don't have to commit changes before they're reflected):

pip install -e C:\repo\directory



ANSWER 3

Score 58


You can do it directly with the HTTPS URL like this:

pip install git+https://github.com/username/repo.git

This also works just appending that line in the requirements.txt in a Django project, for instance.




ANSWER 4

Score 45


It also works with Bitbucket:

pip install git+ssh://git@bitbucket.org/username/projectname.git

Pip will use your SSH keys in this case.