Subject: [bug#54412] [bug#64837] Fix Python on Debian

From: Bogdan <[email-masked]>
Date: Tue, 9 Jan 2024 22:46:51 +0100

Hello.

  Referring to the discussion related to the upcoming release, I
confirm defect #64837 on Debian GNU/Linux 12 (bookworm) and I confirm
that the last patch in #54412 (the one attached in the defect in
Message#14 - https://debbugs.gnu.org/cgi/bugreport.cgi?bug=54412#14,
not the one inlined) fixes the issue.
  I'm also attaching a "double-safe" version, with a simple try-except
added, falling back to the old default, just in case. Also tested,
also fixes the issue.
  You can apply whichever you choose.

--
Regards - Bogdan ('bogdro') D.                 (GNU/Linux & FreeDOS)
X86 assembly (DOS, GNU/Linux):    http://bogdro.evai.pl/index-en.php
Soft(EN): http://bogdro.evai.pl/soft  http://bogdro.evai.pl/soft4asm
www.Xiph.org  www.TorProject.org  www.LibreOffice.org  www.GnuPG.org
From 9eb9f92cd45f2f85e50ff1367319b3af8e5106b9 Mon Sep 17 00:00:00 2001
From: Bogdan Drozdowski <>
Date: Tue, 9 Jan 2024 22:31:57 +0100
Subject: [PATCH] Double-safe patch for Python 3.10

---
 m4/python.m4 | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/m4/python.m4 b/m4/python.m4
index 8d4e4d215..c97ffd203 100644
--- a/m4/python.m4
+++ b/m4/python.m4
@@ -256,7 +256,17 @@ except ImportError:
    am_cv_python_pythondir=`$PYTHON -c "
 $am_python_setup_sysconfig
 if can_use_sysconfig:
-  sitedir = sysconfig.get_path('purelib', vars={'base':'$am_py_prefix'})
+  try:
+    if hasattr(sysconfig, 'get_default_scheme'):
+      scheme = sysconfig.get_default_scheme()
+    else:
+      scheme = sysconfig._get_default_scheme()
+    if scheme == 'posix_local':
+      # Debian's default scheme installs to /usr/local/ but we want to find headers in /usr/
+      scheme = 'posix_prefix'
+    sitedir = sysconfig.get_path('purelib', scheme, vars={'base':'$am_py_prefix'})
+  except:
+    sitedir = sysconfig.get_path('purelib', vars={'base':'$am_py_prefix'})
 else:
   from distutils import sysconfig
   sitedir = sysconfig.get_python_lib(0, 0, prefix='$am_py_prefix')
@@ -298,7 +308,17 @@ sys.stdout.write(sitedir)"`
    am_cv_python_pyexecdir=`$PYTHON -c "
 $am_python_setup_sysconfig
 if can_use_sysconfig:
-  sitedir = sysconfig.get_path('platlib', vars={'platbase':'$am_py_exec_prefix'})
+  try:
+    if hasattr(sysconfig, 'get_default_scheme'):
+      scheme = sysconfig.get_default_scheme()
+    else:
+      scheme = sysconfig._get_default_scheme()
+    if scheme == 'posix_local':
+      # Debian's default scheme installs to /usr/local/ but we want to find headers in /usr/
+      scheme = 'posix_prefix'
+    sitedir = sysconfig.get_path('platlib', scheme, vars={'platbase':'$am_py_exec_prefix'})
+  except:
+    sitedir = sysconfig.get_path('platlib', vars={'platbase':'$am_py_exec_prefix'})
 else:
   from distutils import sysconfig
   sitedir = sysconfig.get_python_lib(1, 0, prefix='$am_py_exec_prefix')
-- 
2.35.1