Install Python packages from git repository with pip

Learn how to install a Python package from a git repository

Posted by Harald Nezbeda on Fri 06 August 2021

When it comes to packages probably every Python developer thinks of pypi. This is the most common way of distribution them in the ecosystem.

But there are several cases where packages are in a progress or pre alfa state in which a package maintaner considers a release is too early. Or in other cases packages are only ment to be used internally. One solution is to install such packages is via git.

Please be aware that the strings used after pip install can be used directly inside the requirements.txt file.

Install via SSH

This is usefull for projects located inside an internal git server or for projects that are not public and require ssh authentication.

pip install git+ssh://git@git.tld/<owner>/<project>

Example: pip install git+ssh://[email protected]/nezhar/django-model-prefix

Install via HTTPS

Probably the most common use case is testing new features in open source repositories and installing modules that are not released on pypi.

pip install git+https://git.tld/<owner>/<project>

Example: pip install git+

Installing a branch, tag or commit

The above commands will only install what is available in the default branch. In most of the cases you want to target a specific branch, tag or maybe even a commit. This can be achieved by providing @ argument to the git string.

Example: pip install git+[email protected]

Providing options for extras_require

Some packages provide extras_require inside or setup.cfg. In order to target them during the installation process, the #egg argument must be provided. As a value in contains the name of the package and the option for the extras_require

Example: pip install git+[email protected]#egg=jsonschema[format]