Similar to Python/LibraryStyleGuide here are some additional approaches.
If you install a single package with scripts and a public module, and would like to provide both python2 and python3 public modules (because you don't know if someone is relying on them), and want to choose which python to use for your scripts you can follow one of these recipes for python2/3 dual packaging.
include /usr/share/dpkg/pkg-info.mk PYTHON2_VERSIONS = $(shell pyversions -r) PYTHON3_VERSIONS = $(shell py3versions -r) py3sdo = set -e; $(foreach py, $(PYTHON3_VERSIONS), $(py) $(1);) pyalldo = set -e; $(foreach py, $(PYTHON2_VERSIONS) $(PYTHON3_VERSIONS), $(py) $(1);) %: dh $@ --with python2,python3 ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS))) override_dh_auto_test: $(call pyalldo, -m unittest discover -vv test/) endif override_dh_auto_build: dh_auto_build $(call py3sdo, setup.py build) override_dh_auto_install: # whichever called last, will result in shebang update # in this case, the scripts will end up with python3 shebang # reverse the order if you want to continue using python2 shebang dh_auto_install $(call py3sdo, setup.py install --root=$(CURDIR)/debian/$(DEB_SOURCE) --install-layout=deb) override_dh_auto_clean: dh_auto_clean rm -rf build rm -rf *.egg-info
If you don't like GNU Make $(call) function
include /usr/share/dpkg/pkg-info.mk PYTHON2_VERSIONS = $(shell pyversions -r) PYTHON3_VERSIONS = $(shell py3versions -r) %: dh "$@" --with python2,python3 override_dh_auto_clean: dh_auto_clean rm -rf build override_dh_auto_build: dh_auto_build set -ex; for python in $(PYTHON3_VERSIONS); do \ $$python setup.py build; \ done override_dh_auto_install: dh_auto_install set -ex; for python in $(PYTHON3_VERSIONS); do \ $$python setup.py install --root=$(CURDIR)/debian/$(DEB_SOURCE) --install-layout=deb; \ done