35

It is possible to specify in Pipfile packages from custom Git repository. But I cannot find comprehensive documentation on how to specify the concrete branch or a commit to be used for installation.

Is there a complete reference on how to use Git URLs for python packages in the Pipfile that are supported by the pipenv for specifying custom branches, versions, or commits?

It would be really nice to have it with equivalent pipenv command line arguments.

Michael
  • 8,362
  • 6
  • 61
  • 88
kuza
  • 2,761
  • 3
  • 22
  • 56

2 Answers2

46

Here is some documentation on the GitHub repo for pipenv:

You can install packages with pipenv from git and other version control systems using URLs formatted according to the following rule:

<vcs_type>+<scheme>://<location>/<user_or_organization>/<repository>@<branch_or_tag>#egg=<package_name>

So, for example:

[packages]
requests = {git = "https://github.com/requests/requests.git", editable = true, ref = "v2.20.1"}

You can generate a Pipfile using the command line. The Pipfile above was generated with:

pipenv install -e git+https://github.com/requests/requests.git@v2.20.1#egg=requests

The documentation for pip goes into more detail.

Michael
  • 8,362
  • 6
  • 61
  • 88
Alex W
  • 37,233
  • 13
  • 109
  • 109
  • I was successfully installing our packages from GIT referring to this documentation while I have totally forgotten about this question of mine asked before such information was available. The first reference of the [VCS](https://github.com/pypa/pipenv/commit/bcad23874f60469a6e4faab41c795550f024b195) committed on Sep 20, 2017, did not mention the possibility of specifying branches until [this](https://github.com/pypa/pipenv/commit/a3162945be79182d0a4b4a7c140970dc340788fb) edit was committed on Aug 12, 2018. Maybe this answer a good candidate for a community wiki? – kuza Dec 16 '18 at 15:29
  • 1
    This worked for me, but note that the "egg" needs to be the *original project name,* not some other name you define in the misguided attempt to avoid a naming conflict. :-) – Nick K9 Dec 27 '22 at 16:30
0

pip package archives

In addition to Alex's excellent answer, you can also use pip's "archive" format on a zipped copy of the repository. Several code hosts automatically provide zip files at predictable URLs.

Why would I do this?

The VCS installation works perfectly fine. This alternative is convenient if the machine you're installing on does not have Git, like a "slim" container image. Previous reports suggested that this method was faster than Git, but they seem comparable now.

Examples

Replace the tokens with the values you want in the code samples below.

Field Description
<package> The name of the package. (Match the package's name from its setup.py!)
<user> The repository owner
<repo> The repository name
<refname> Branch, tag, or commit SHA. Bitbucket can also use default for the default branch.

Pipfile

[packages]
<package> = {file = "https://github.com/<user>/<repo>/archive/<refname>.zip"}
<package> = {file = "https://bitbucket.org/<user>/<repo>/get/<refname>.zip"}
<package> = {file = "https://codeberg.org/<user>/<repo>/archive/<refname>.zip"}
<package> = {file = "https://gitlab.com/<user>/<repo>/-/archive/<refname>/<repo>-<refname>.zip"}

CLI installation

pipenv install https://github.com/<user>/<repo>/archive/<refname>.zip
pipenv install https://bitbucket.org/<user>/<repo>/get/<refname>.zip
pipenv install https://codeberg.org/<user>/<repo>/archive/<refname>.zip
pipenv install https://gitlab.com/<user>/<repo>/-/archive/<refname>/<repo>-<refname>.zip

Warning

There are reports from 2017 and 2018 that unlike pip, pipenv will not recursively install dependencies from zips. Dependencies are working fine for me, though. This commit from September 2018 is my best guess for when things changed, but if you know otherwise, please comment or edit.

Michael
  • 8,362
  • 6
  • 61
  • 88