pip install from git repo branch

Trying to pip install a repo’s specific branch. Google tells me to

pip install https://github.com/user/<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3e4c5b4e511059574a7e5c4c5f505d56">[email protected]</a>

The branch’s name is issue/34/oscar-0.6 so I did pip install https://github.com/tangentlabs/[email protected]/issue/34/oscar-0.6 but its returning a 404.

How do I install this branch?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Prepend the url prefix git+ (See VCS Support):

pip install git+https://github.com/tangentlabs/<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="422628232c252d6f2d312123306f32233b32232e6c252b36022b31313727">[email protected]</a>/34/oscar-0.6

And specify the branch name without the leading /.

Method 2

Using pip with git+ to clone a repository can be extremely slow (test with https://github.com/django/[email protected]/1.6.x for example, it will take a few minutes). The fastest thing I’ve found, which works with GitHub and BitBucket, is:

pip install https://github.com/user/repository/archive/branch.zip

which becomes for Django master:

pip install https://github.com/django/django/archive/master.zip

for Django stable/1.7.x:

pip install https://github.com/django/django/archive/stable/1.7.x.zip

With BitBucket it’s about the same predictable pattern:

pip install https://bitbucket.org/izi/django-admin-tools/get/default.zip

Here, the master branch is generally named default.
This will make your requirements.txt installing much faster.

Some other answers mention variations required when placing the package to be installed into your requirements.txt. Note that with this archive syntax, the leading -e and trailing #egg=blah-blah are not required, and you can just simply paste the URL, so your requirements.txt looks like:

https://github.com/user/repository/archive/branch.zip

Method 3

Instructions to install from private repo using ssh credentials:

$ pip install git+ssh://<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a5c2ccd1e5c2ccd1cdd0c78bc6cac8">[email protected]</a>/myuser/<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="74121b1b5a131d0034190d">[email protected]</a>_version

To install a package from a subdirectory, say stackoverflow

$ pip install git+ssh://<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1f78766b5f78766b776a7d317c7072">[email protected]</a>/myuser/<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="22444d4d0c454b56624f5b">[email protected]</a>_version#subdirectory=stackoverflow

https://pip.pypa.io/en/stable/topics/vcs-support/

Method 4

Just to add an extra, if you want to install it in your pip file it can be added like this:

-e git+https://github.com/tangentlabs/<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="74101e151a131b591b071715065904150d0415185a131d00341d07070111">[email protected]</a>/34/oscar-0.6#egg=django-oscar-paypal

It will be saved as an egg though.

Method 5

This worked like charm:

pip3 install git+https://github.com/deepak1725/<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="17717675657e742f3a7679767b6e637e74643a6078657c726539707e6357737261727b7867">[email protected]</a>

Where :

develop: Branch

fabric8-analytics-worker.git : Repo

deepak1725: user

Method 6

You used the egg files install procedure.
This procedure supports installing over git, git+http, git+https, git+ssh, git+git and git+file. Some of these are mentioned.

It’s good you can use branches, tags, or hashes to install.

@Steve_K noted it can be slow to install with “git+” and proposed installing via zip file:

pip install https://github.com/user/repository/archive/branch.zip

Alternatively, I suggest you may install using the .whl file if this exists.

pip install https://github.com/user/repository/archive/branch.whl

It’s pretty new format, newer than egg files. It requires wheel and setuptools>=0.8 packages. You can find more in here.

Method 7

to me your suggestion from question work e.g.

pip install https://github.com/user/<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e39186938ccd848a97a38191828d808b">[email protected]</a>

translating concretely to doing

pip install -U git+https://github.com/moskomule/<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5f3e313e2b30323a7138362b1f3b3a29">[email protected]</a>

worked. Perhaps remove the extra / is redundant. My output:

(original_anatome_env) brando~/ultimate-anatome ❯ pip install -U git+https://github.com/moskomule/<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4a2b242b3e25272f642d233e0a2e2f3c">[email protected]</a>
Collecting git+https://github.com/moskomule/<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ff9e919e8b90929ad198968bbf9b9a89">[email protected]</a>
  Cloning https://github.com/moskomule/anatome.git (to revision dev) to /private/var/folders/x4/0xq0brj57xz3dbhbmblypbm00000gr/T/pip-req-build-62d_ghd2
  Running command git clone -q https://github.com/moskomule/anatome.git /private/var/folders/x4/0xq0brj57xz3dbhbmblypbm00000gr/T/pip-req-build-62d_ghd2
  Running command git checkout -b dev --track origin/dev
  Switched to a new branch 'dev'
  Branch 'dev' set up to track remote branch 'dev' from 'origin'.
  Resolved https://github.com/moskomule/anatome.git to commit 4b576e51cb1824a57ea04974e0f92b5a6143294d
Requirement already satisfied: torch>=1.10.0 in /Users/brando/anaconda3/envs/metalearning/envs/original_anatome_env/lib/python3.9/site-packages (from anatome==0.0.6) (1.10.0)
Requirement already satisfied: torchvision>=0.11.1 in /Users/brando/anaconda3/envs/metalearning/envs/original_anatome_env/lib/python3.9/site-packages (from anatome==0.0.6) (0.11.1)
Requirement already satisfied: typing-extensions in /Users/brando/anaconda3/envs/metalearning/envs/original_anatome_env/lib/python3.9/site-packages (from torch>=1.10.0->anatome==0.0.6) (3.10.0.2)
Requirement already satisfied: pillow!=8.3.0,>=5.3.0 in /Users/brando/anaconda3/envs/metalearning/envs/original_anatome_env/lib/python3.9/site-packages (from torchvision>=0.11.1->anatome==0.0.6) (8.4.0)
Requirement already satisfied: numpy in /Users/brando/anaconda3/envs/metalearning/envs/original_anatome_env/lib/python3.9/site-packages (from torchvision>=0.11.1->anatome==0.0.6) (1.21.4)
Building wheels for collected packages: anatome
  Building wheel for anatome (setup.py) ... done
  Created wheel for anatome: filename=anatome-0.0.6-py3-none-any.whl size=10167 sha256=63b12a36f33deb8313bfe7756be60bd08915b8ba36711be47e292b590df70f61
  Stored in directory: /private/var/folders/x4/0xq0brj57xz3dbhbmblypbm00000gr/T/pip-ephem-wheel-cache-rde_ngug/wheels/19/e4/be/01479e8cba62ae8cdcd501cd3bf49e199f2bb94732a6a1b006
Successfully built anatome
Installing collected packages: anatome
  Attempting uninstall: anatome
    Found existing installation: anatome 0.0.5
    Uninstalling anatome-0.0.5:
      Successfully uninstalled anatome-0.0.5
Successfully installed anatome-0.0.6

0.6.0 is the dev branch version number and 0.5.0 is the master, so it worked!

Method 8

Pip is a package manager of python. You can download Python libraries from some Python repositories like PyPI. You can also download libraries from a git repository. This is gonna be the issue to be explained in this article.

As you may know, you can use two protocols which are http and ssh to do something on git repositories. Using protocol ssh instead of http may provide some ease of use. Because of nature of ssh, you can do something with your primary/public keys. So, you don’t have to input your credentials all the time. But I’ll be giving a way for both;

Here are the example with Github repositories;

For HTTP

pip install git+https://github.com/<project_owner>/<project_name>

For SSH

pip install git+ssh://[email protected]/<project_owner>/<project_name>.git

For Local Git Repository

pip install git+file///path/to/your/git/project/

Installing a special 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/[email protected]

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/[email protected]#egg=jsonschema[format]

Method 9

For windows & pycharm setup:

If you are using pycharm and If you want to use pip3 install git+https://github.com/...

  • firstly, you should download git from https://git-scm.com/downloads
  • then restart pycharm
  • and you can use pycharm terminal to install what you want

pip install from git repo branch


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x