This is a short post to demonstrate how to install packages directly from GitHub with pyprojects.toml
or requirements.txt
, including custom branches and commits.
It will focus on pyprojects.toml
because this is newer and there’s less information about it, but the general pattern holds for requirements.txt
as well.
In pyproject.toml
, you can specify dependencies for a project via the dependencies
field.
For example, to specify Sphinx as a dependency:
However, this will install the version that is published to [PyPI
](Here’s how to install a specific branch in pyproject.toml
:
).
What if you want to install from @main
, or from a specific commit or branch?
To do so, use a pattern like this:
Here are a few recipes for doing this:
Install directly from GitHub¶
Install from a specific branch¶
With requirements.txt
¶
Using these patterns with requirements.txt
is nearly the same, but it’s a bit simpler.[1]
You don’t need to specify the packagename@
pattern used above.
You can simply add a line that points to git like this:
This will install from the default branch. You can also specify specific branches or eggs in the same way as above.
Thanks to Matthew Feickhart for reminding me of this.