This answer has been updated as Python has evolved over the years.
Scroll to the bottom for the most current answer, or read through to see how this has evolved.
Unfortunately the accepted answer does not work with private repositories, which is one of the most common use cases for this.
2019 - dependency_links (deprecated as of pip v19+)
I eventually did get it working with a setup.py
file that looks like this method:
from setuptools import setup, find_packages
setup(
name = 'MyProject',
version = '0.1.0',
url = '',
description = '',
packages = find_packages(),
install_requires = [
# Github Private Repository - needs entry in `dependency_links`
'ExampleRepo'
],
dependency_links=[
# Make sure to include the `#egg` portion so the `install_requires` recognizes the package
'git+ssh://[email protected]/example_org/ExampleRepo.git#egg=ExampleRepo-0.1'
]
)
Newer versions of pip make this even easier by removing the need to use "dependency_links"-
from setuptools import setup, find_packages
setup(
name = 'MyProject',
version = '0.1.0',
url = '',
description = '',
packages = find_packages(),
install_requires = [
# Github Private Repository
'ExampleRepo @ git+ssh://[email protected]/example_org/ExampleRepo.git#egg=ExampleRepo-0.1'
]
)
However, with the very latest pip you'll run into issues with the EGG format handler. This is because while the egg is ignored pip is now doing direct URL matching and will consider two URLs, one with the egg fragment and the other without, to be completely different versions even if they point to the same package. As such it's best to leave any egg fragments off.
2021 June - setup.py
So, the best way (current to June 2021) to add a dependency from Github to your setup.py that will work with public and private repositories:
from setuptools import setup, find_packages
setup(
name = 'MyProject',
version = '0.1.0',
url = '',
description = '',
packages = find_packages(),
install_requires = [
# Github Private Repository
'ExampleRepo @ git+ssh://[email protected]/example_org/ExampleRepo.git'
]
)
2022 February - setup.cfg
Apparently setup.py is being deprecated (although my guess is it'll be around for awhile) and setup.cfg is the new thing.
[metadata]
name = MyProject
version = 0.1.1
[options]
packages = :find
install_requires =
ExampleRepo @ git+ssh://[email protected]/example_org/ExampleRepo.git
2022 June - pyproject.toml
setup.cfg is already "pre" deprecated. as setuptools now has experimental support for pyproject.toml files.
This is the future, but since this is still experimental it should not be used in real projects for now. Even though setup.cfg
is on its way out you should use it for a declarative format, otherwise setup.py is still the way to go. This answer will be updated when setuptools has stabilized their support of the new standard.
2023 January - pyproject.toml
It is now possible to define all of your dependencies in pyproject.toml
. Other options such as setup.cfg still work.
[build-system]
requires = ["setuptools", "setuptools-scm"]
build-backend = "setuptools.build_meta"
[project]
dependencies = [
'ExampleRepo @ git+ssh://[email protected]/example_org/ExampleRepo.git',
]
[project.optional-dependencies]
dev = ['ExtraExample @ git+ssh://[email protected]/example_org/ExtraExample.git']
2024 April
At this point the pyproject.toml
file is the standard. There is literally no reason to use setup.cfg
or setup.py
(but they still work). If you are using them you should consolidate to a single pyproject.toml
file.