Install Python Packages Hosted On Private GitHub
Unfortunately, GitHub does not provide the ability to create a token that is restricted to a specific respository. This is unlike GitLab where one could create a project access token.
Thus, for this tutorial, we will make use of "deploy keys" that are SSH keys we have added to GitHub for specific packages.
Prerequisites / Assumptions
- We are assuming you already have a private GitHub respository for a python package.
- Your repository needs to be set up correctly as a python package, with its
setup.pyat the root/top level of your GitHub repository. You cannot have it within a subfolder.
- You need the ability to create GitHub deploy keys on the repository.
Add the SSH key to your SSH agent, so that it will automatically be used when applicable.
The following examples are lines you would add to your
requirements.txt file, or passed to a pip command.
Each of them require the
my-package-name is the name of your package.
Here we use a branch called
Here we use use a tagged version where the tag is called
Once you have the relevant line you can install through a requirements file with:
pip install --requirement requirements.txt
... or you can install directly with:
pip3 install $LOCATION
- Fernando Freitas Alves - Pip Installing a Package From a Private Repository
- Stack Overflow - How to state in requirements.txt a direct github source
- Adam Johnson - 'pip install' From a Git Repository
First published: 29th July 2021