pythongithubpiprequirements.txt

How to state in requirements.txt a direct github source


I've installed a library using the command

pip install git+git://github.com/mozilla/elasticutils.git

which installs it directly from a Github repository. This works fine and I want to have that dependency in my requirements.txt. I've looked at other tickets like this but that didn't solve my problem. If I put something like

-f git+git://github.com/mozilla/elasticutils.git
elasticutils==0.7.dev

in the requirements.txt file, a pip install -r requirements.txt results in the following output:

Downloading/unpacking elasticutils==0.7.dev (from -r requirements.txt (line 20))
  Could not find a version that satisfies the requirement elasticutils==0.7.dev (from -r requirements.txt (line 20)) (from versions: )
No distributions matching the version for elasticutils==0.7.dev (from -r requirements.txt (line 20))

The documentation of the requirements file does not mention links using the git+git protocol specifier, so maybe this is just not supported.

Does anybody have a solution for my problem?


Solution

  • Normally your requirements.txt file would look something like this:

    package-one==1.9.4
    package-two==3.7.1
    package-three==1.0.1
    ...
    

    To specify a Github repo, you do not need the package-name== convention.

    The examples below update package-two using a GitHub repo. The text after @ denotes the specifics of the package.

    Specify commit hash (41b95ec in the context of updated requirements.txt):

    package-one==1.9.4
    package-two @ git+https://github.com/owner/repo@41b95ec
    package-three==1.0.1
    

    Specify branch name (main):

    package-two @ git+https://github.com/owner/repo@main
    

    Specify tag (0.1):

    package-two @ git+https://github.com/owner/repo@0.1
    

    Specify release (3.7.1):

    package-two @ git+https://github.com/owner/repo@releases/tag/v3.7.1
    

    Note that in certain versions of pip you will need to update the package version in the package's setup.py, or pip will assume the requirement is already satisfied and not install the new version. For instance, if you have 1.2.1 installed, and want to fork this package with your own version, you could use the above technique in your requirements.txt and then update setup.py to 1.2.1.1.

    See also the pip documentation on VCS support.