'pip install' From a Git Repository2019-03-11
It’s quite common to want to
pip install a version of a package that hasn’t
been released to PyPI, but is available on its Git repository host, such as
GitHub. If the package is pure Python or has a relatively simple build process
setup.py, it can be installed from source.
Installing via Git
Pip can speak
git to do this through its VCS Support.
For example, to install Django’s most recent commit
at time of writing, we can run:
Installing via tarballs
An alternative that avoids Git is to install from a tarball URL, that the major hosted Git solutions provide, for example:
Either format is slower than using a package on PyPI, because the download will
be executed every time the install is run, which you might do with
-r requirements.txt on every build. However the tarball formats save a lot of
downloading because only the tip of the repository will be downloaded, and not
the full history, which can be very big for something like Django!
Also if you need a package with extra requirements, for example
which ensures Django gets all the requirements it needs for password hashing,
#egg argument on the end of the URL. For example:
For comparison, on a 100MB/s internet connection, I find the git clone for Django takes 36s while the tarball install takes 15s - less than half the time. Installing from PyPI, where a wheel is available, takes just 5s.
The ideal situation is thus to install from PyPI. If an upstream package hasn’t
released in a while, it’s worth asking them to, or offering to help with
maintenance. Otherwise it is also possible to fork it and publish it on PyPI
with a namespace prefix, for example publish your
django fork as
There’s a lot more options for sources in the
pip install docs,
but installing from tarball URL’s is the most common piece of advice I find
Hope that helps,
Want better tests? Check out my book Speed Up Your Django Tests which teaches you to write faster, more accurate tests.
One summary email a week, no spam, I pinky promise.
© 2021 All rights reserved.