Pip & Git

As people commonly do, we claim requirements in requirements.txt file. When we need a library, just add a line such as library==0.1.0.

If we need to install library from Git, pip enable us to do that. pip currently supports cloning over git, git+https and git+ssh:

git+ssh://[email protected]/org/repo.git#egg=repo
git+https://ghe.domain.com/org/repo.git#egg=repo
[email protected]:org/repo.git#egg=repo

We can also passing branch names, a commit hash or a tag name as an url anchor:

git+ssh://[email protected]/org/[email protected]#egg=repo

We must know there are 2 types of installing mode:

  • for editable mode, by adding -e option, pip will install library by cloning project into a src directory, which means source code included.
  • for non-editable mode, the project is built locally in a temp dir and then installed normally.
-e git+ssh://[email protected]/org/repo.git#egg=repo

Q: How to choose these modes?

A: If you have tagged git commit to a specified version, just use non-editable mode.

Normally, we will append version to egg is used by pip in its dependency logic to identify the project prior to pip downloading and analyzing the metadata. The optional “version” component of the egg name is extremely important if you want to upgrade library in non-editable mode. The format of egg is like #egg=library-0.1.0:

git+ssh://[email protected]/lws/[email protected]#egg=flask_ldap-0.5.0