diff --git a/Rules b/Rules
index fe18ce5..34165be 100644
--- a/Rules
+++ b/Rules
@@ -108,11 +108,16 @@ endif
 
 .PHONY: others tests bench bench-build
 
+ifdef PYTHON
 # Test programs for the pretty printers.
 tests-printers-programs := $(addprefix $(objpfx),$(tests-printers))
 
 # .out files with the output of running the pretty printer tests.
 tests-printers-out := $(patsubst %,$(objpfx)%.out,$(tests-printers))
+else
+# Unset tests-printers if we don't have PYTHON.
+tests-printers =
+endif
 
 ifeq ($(build-programs),yes)
 others: $(addprefix $(objpfx),$(others) $(sysdep-others) $(extra-objs))
@@ -255,16 +260,8 @@ endif
 
 endif	# tests
 
+ifdef PYTHON
 ifneq "$(strip $(tests-printers))" ""
-# We're defining this here for now; later it'll be defined at configure time
-# inside Makeconfig.
-PYTHON := python
-
-# Invoke Python using -B to avoid generating .pyc files on the source dir,
-# so that we can keep it read-only.
-python-flags := -B
-
-python-invoke := $(PYTHON) $(python-flags)
 
 # Static pattern rule for building the test programs for the pretty printers.
 $(tests-printers-programs): %: %.o $(tests-printers-libs) \
@@ -283,9 +280,10 @@ py-env := PYTHONPATH=$(py-const-dir):$(..)scripts:$${PYTHONPATH}
 $(tests-printers-out): $(objpfx)%.out: $(objpfx)% %.py %.c $(pretty-printers) \
 		       $(..)scripts/test_printers_common.py
 	$(test-wrapper-env) $(py-env) \
-	    $(python-invoke) $*.py $*.c $(objpfx)$* $(pretty-printers) > $@; \
+	    $(PYTHON) $*.py $*.c $(objpfx)$* $(pretty-printers) > $@; \
 	$(evaluate-test)
 endif
+endif
 
 
 .PHONY: distclean realclean subdir_distclean subdir_realclean \
diff --git a/benchtests/Makefile b/benchtests/Makefile
index ba4d068..c1d2781 100644
--- a/benchtests/Makefile
+++ b/benchtests/Makefile
@@ -18,8 +18,6 @@
 # Makefile for benchmark tests.  The only useful target here is `bench`.
 # Add benchmark functions in alphabetical order.
 
-PYTHON := python
-
 subdir := benchtests
 
 include ../Makeconfig
@@ -141,7 +139,11 @@ bench-clean:
 	rm -f $(timing-type) $(addsuffix .o,$(timing-type))
 	rm -f $(addprefix $(objpfx),$(bench-extra-objs))
 
+# Define the bench target only if the target has a usable python installation.
+ifdef PYTHON
 bench: bench-build bench-set bench-func bench-malloc
+endif
+
 # Target to only build the benchmark without running it.  We generate locales
 # only if we're building natively.
 ifeq (no,$(cross-compiling))
diff --git a/config.make.in b/config.make.in
index d2d9b8a..35e7e59 100644
--- a/config.make.in
+++ b/config.make.in
@@ -126,6 +126,7 @@ MSGFMT = @MSGFMT@
 BASH = @BASH_SHELL@
 AWK = @AWK@
 PERL = @PERL@
+PYTHON = @PYTHON@
 
 # Additional libraries.
 LIBGD = @LIBGD@
diff --git a/configure b/configure
index 5cf3230..10b0fb7 100755
--- a/configure
+++ b/configure
@@ -639,6 +639,8 @@ CXX_CMATH_HEADER
 CXX_CSTDLIB_HEADER
 CXX_SYSINCLUDES
 SYSINCLUDES
+PYTHON
+PYTHON_PROG
 AUTOCONF
 NM
 AWK
@@ -5086,17 +5088,73 @@ else
   AUTOCONF=no
 fi
 
+# Check for python3 if available, or else python.
+for ac_prog in python3 python
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_PYTHON_PROG+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$PYTHON_PROG"; then
+  ac_cv_prog_PYTHON_PROG="$PYTHON_PROG" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_PYTHON_PROG="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+PYTHON_PROG=$ac_cv_prog_PYTHON_PROG
+if test -n "$PYTHON_PROG"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PYTHON_PROG" >&5
+$as_echo "$PYTHON_PROG" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$PYTHON_PROG" && break
+done
+test -n "$PYTHON_PROG" || PYTHON_PROG="no"
+
+case "x$PYTHON_PROG" in
+xno|x|x:) PYTHON_PROG=no ;;
+*) ;;
+esac
+
+if test "x$PYTHON_PROG" = xno; then
+  aux_missing="$aux_missing python"
+else
+  PYTHON="$PYTHON_PROG -B"
+
+fi
+
 test -n "$critic_missing" && as_fn_error $? "
 *** These critical programs are missing or too old:$critic_missing
 *** Check the INSTALL file for required versions." "$LINENO" 5
 
 test -n "$aux_missing" && { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING:
 *** These auxiliary programs are missing or incompatible versions:$aux_missing
-*** some features will be disabled.
+*** some features or tests will be disabled.
 *** Check the INSTALL file for required versions." >&5
 $as_echo "$as_me: WARNING:
 *** These auxiliary programs are missing or incompatible versions:$aux_missing
-*** some features will be disabled.
+*** some features or tests will be disabled.
 *** Check the INSTALL file for required versions." >&2;}
 
 # if using special system headers, find out the compiler's sekrit
diff --git a/configure.ac b/configure.ac
index d719fad..aa6e2d7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1050,13 +1050,27 @@ else
   AUTOCONF=no
 fi
 
+# Check for python3 if available, or else python.
+AC_CHECK_PROGS(PYTHON_PROG, python3 python,no)
+case "x$PYTHON_PROG" in
+xno|x|x:) PYTHON_PROG=no ;;
+*) ;;
+esac
+
+if test "x$PYTHON_PROG" = xno; then
+  aux_missing="$aux_missing python"
+else
+  PYTHON="$PYTHON_PROG -B"
+  AC_SUBST(PYTHON)
+fi
+
 test -n "$critic_missing" && AC_MSG_ERROR([
 *** These critical programs are missing or too old:$critic_missing
 *** Check the INSTALL file for required versions.])
 
 test -n "$aux_missing" && AC_MSG_WARN([
 *** These auxiliary programs are missing or incompatible versions:$aux_missing
-*** some features will be disabled.
+*** some features or tests will be disabled.
 *** Check the INSTALL file for required versions.])
 
 # if using special system headers, find out the compiler's sekrit
