5

Install Python packages from git repository with pip

 2 years ago
source link: https://nezhar.com/blog/install-python-packages-from-git-repository-with-pip/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Install Python packages from git repository with pip

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://[email protected]/<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+https://github.com/nezhar/django-model-prefix

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+https://github.com/nezhar/django-model-prefix@a5cabf1ac210b6358ea358b1d268d802114d85d4

Providing options for extras_require

Some packages provide extras_require inside setup.py 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+https://github.com/anexia-it/jsonschema@draft2020-12#egg=jsonschema[format]


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK