Search code examples
pythongithubpypi

Should put in requirements.txt dependency targeting package in pypi or github repo?


Are there any technical indications to prefer referencing a package on PyPI over the original source on GitHub in requirements.txt?

Only thing that comes to my mind is that freezing a package on a certain version is very cumbersome with GitHub (package==1.0.0 vs git://github.com/{ username }/{ reponame }.git@{ tag name }#egg={ desired egg name }), but I'm not sure if this can cause any problems.

Other thing is necessity to install git on target machine.

Are there any other indications?


Solution

  • PyPI is the accepted defacto location for distributing released versions of a package, and it could be that not all Python packaging tools support installing from GitHub.

    And as you already noticed, for pip to support GitHub you must have git installed; this limits portability of your file.

    Next, not all project maintainers remember to tag releases in GitHub; what is distributed to PyPI may be hard to locate on GitHub. The tag could also be wrong. You could end up installing a subtly different version from PyPI, creating confusion when you run into a support issue.

    On the other hand, if you must install a non-released development version (say, you need a critical bugfix but no release has been rolled since), then GitHub may be the only place you can get that version.

    So, in short, you should prefer using PyPI over GitHub, as that ensures that you got an official release, and is more portable. Only use a GitHub URL in requirements.txt if there is no other source for a specific version.