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:
dependencies = [
"sphinx",
]
pyproject.toml
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:
dependencies = [
"<packagename>@git+<url-to-repo>#egg=<branch or hash>",
]
pyproject.toml
Here are a few recipes for doing this:
Install directly from GitHub¶
dependencies = [
"sphinx@git+https://github.com/sphinx-doc/sphinx",
]
pyproject.toml
Install from a specific branch¶
dependencies = [
"sphinx@git+https://github.com/sphinx-doc/sphinx#egg=branchname",
]
pyproject.toml
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:
requirement1
requirement2
git+https://github.com/pydata/pydata-sphinx-theme
requirements.txt
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.