Can pip install packages from a private GitHub repository?

I’m trying to install a Python package from a private GitHub repository, but I’m facing some challenges. When I use the command for a public repository, it works fine:

pip install git+git://github.com/django/django.git

However, I encounter issues when attempting the same for a private repository:

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

The output I see is:

Downloading/unpacking git+git://github.com/echweb/echweb-utils.git
Cloning Git repository git://github.com/echweb/echweb-utils.git...
fatal: The remote end hung up unexpectedly
Command failed with error code 128

I believe this is due to my lack of authentication for the private repository. I then attempted to use SSH to authenticate:

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

But I received a permission error:

Cloning Git repository ssh://github.com/echweb/echweb-utils.git...
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
Command failed with error code 128

Is it feasible to install a package from a private repo using pip? If so, what steps should I take?

you can also use pip’s built-in credential helper. just create a .netrc file in your home directory with your github creds - saves tons of typing. format it like machine github.com login yourusername password yourtoken. then pip install git+https://github.com/echweb/echweb-utils.git works without stuffing credentials in the url.

ssh method works gr8 once you get your keys set up right. Add your ssh key to github first, then test it with ssh -T [email protected]. Try this URL instead: git+ssh://[email protected]/echweb/echweb-utils.git - ur missing the git@ part.

I like using requirements.txt with HTTPS format instead. Had the same auth issues and this approach is way cleaner for long-term dependency management. Just create a requirements.txt file and add: git+https://github.com/echweb/echweb-utils.git. Then run pip install -r requirements.txt. It’ll prompt for your GitHub username and personal access token. No credentials stuck in your command history, which is a security nightmare. The token gets cached temporarily so you won’t need to re-enter it during the same session. Way safer than embedding tokens in URLs.

Had this exact problem and here’s what fixed it. It’s definitely an authentication issue. For private repos, you need HTTPS with a personal access token instead of the git protocol.

Generate a personal access token in your GitHub settings with repo permissions. Then use:

pip install git+https://username:[email protected]/echweb/echweb-utils.git

Swap ‘username’ for your GitHub username and ‘token’ for your access token. Works every time for me. SSH can work too, but it’s trickier since you need proper key setup - more hassle to debug if your keys aren’t configured right.

I use environment variables for the token - saves tons of headaches. Set GIT_TOKEN in your environment, then run pip install git+https://${GIT_TOKEN}@github.com/echweb/echweb-utils.git. Keeps the token out of your shell history and works across different private repos. The git protocol doesn’t support authentication at all - that’s why it’s hanging. HTTPS beats SSH in CI/CD environments since SSH keys get finicky across different systems. Just double-check your token has the right scopes in GitHub settings.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.