9

I know I can install the master branch with:

pip install git+https://github.com/USER/REPO

I also know I can install a specific release with:

pip install git+https://github.com/USER/REPO@RELEASE

But is there a way to install the latest release (the one GitHub returns at https://github.com/USER/REPO/releases/latest)? I've tried the following:

pip install git+https://github.com/USER/REPO@latest

but it fails:

ERROR: Command errored out with exit status 1: git checkout -q latest

EDIT: This question is not a duplicate of Pip doesn't install latest GitHub release. The latter is about how to install a specific release and/or from the master branch, but not from the latest release.

torek
  • 448,244
  • 59
  • 642
  • 775
Roméo Després
  • 1,777
  • 2
  • 15
  • 30
  • 1
    Does this answer your question? [Pip doesn't install latest GitHub release](https://stackoverflow.com/questions/20814857/pip-doesnt-install-latest-github-release) – imxitiz Jul 09 '21 at 10:50

2 Answers2

2

You can use the github API. Something like

pip install "git+https://github.com/USER/REPO@$(curl -s https://api.github.com/repos/USER/REPO/releases/latest | jq -r ".tag_name")"

would probably work for you. If you don't feel like installing jq, there's e.g. this gist.

1

This might be a bad idea, but you can grab the latest tarball url from GitHub's rest API:

pip install \
 $(python3 -c "import urllib.request, json, sys; \
 u=json.loads(urllib.request.urlopen('https://api.github.com/repos/USER/REPO/releases/latest').read().decode()).get('tarball_url', False);\
 print(u) if u else sys.exit(1);")

Which you drop into pip install using command substitution $(..)

There should be a couple of options available, either tarball_url and zipball_url and pip should be able to download these.

Alex
  • 6,610
  • 3
  • 20
  • 38