This quick tutorial will cover how to to install packages from github using pip and pipenv.
Recently, I was updating the packages of an old project. Everything seemed to be going smoothly, until one of the updated packages broke my application.
After scrolling through some issues on the package’s github, I found out the package version available through pip on pypi differed from the version available in the package’s master branch.
At first, I tried to revert that package to an older version, hoping that would solve the problem. Unfortunately, all older versions of the package were incompatible with the most recent version of the django rest framework.
It seemed like I would either have to wait for the maintainer to update the package on pypi or inelegantly clone the repo and include the code directly myself forgoing the version management of pipenv.
Luckily, I found a different solution.
It turns out that both pip and pipenv allow you to install a package directly from github.
The syntax for installing a package directly from git looks like this:
pipenv install git+<package_path>.git@<branch>#egg=<package_name>
pip install git+<package_path>.git@<branch>
Here’s an example using the Django package.
pipenv install git+https://github.com/django/django.git@master#egg=django
pip install git+https://github.com/django/django.git@master
Isn’t that awesome? Now you can install packages even if they aren’t available on pypi.
I hope this was helpful.
For more python tips, tricks, and guides you can check here.