‘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 integrated with
setup.py, it can be installed from source.
$ python -m pip install git+https://github.com/django/django.git@45dfb3641aa4d9828a7c5448d11aa67c7cbd7966
An alternative that avoids Git is to install from a tarball URL, that the major hosted Git solutions provide, for example:
$ # GitHub $ python -m pip install https://github.com/django/django/archive/45dfb3641aa4d9828a7c5448d11aa67c7cbd7966.tar.gz $ # GitLab $ python -m pip install https://gitlab.com/pycqa/flake8/-/archive/3.7.7/flake8-3.7.7.tar.gz $ # Bitbucket $ python -m pip install https://bitbucket.org/hpk42/tox/get/2.3.1.tar.gz
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
pip install -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
django[argon2] which ensures Django gets all the requirements it needs for password hashing, add the
#egg argument on the end of the URL.
$ # Git repo $ python -m pip install git+https://github.com/django/django.git@45dfb3641aa4d9828a7c5448d11aa67c7cbd7966#egg=django[argon2] $ # Tarball $ python -m pip install https://github.com/django/django/archive/45dfb3641aa4d9828a7c5448d11aa67c7cbd7966.tar.gz#egg=django[argon2]
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 myself giving.
Hope that helps,
If your Django project’s long test runs bore you, my book can help.
One summary email a week, no spam, I pinky promise.
Tags: pip, python
© 2019 All rights reserved.