From a25fc5281811c7f480026fe701c3b0ae2581c037 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=D0=9A=D0=BE=D1=80=D0=B5=D0=BD=D0=B1=D0=B5=D1=80=D0=B3=20?= =?utf8?q?=D0=9C=D0=B0=D1=80=D0=BA?= Date: Sun, 11 Jun 2023 09:59:36 +0300 Subject: [PATCH] Fix: #895: pythonmodule: add all site-packages directories to sys.path --- pythonmod/pythonmod.c | 40 ++++------------------------------------ 1 file changed, 4 insertions(+), 36 deletions(-) diff --git a/pythonmod/pythonmod.c b/pythonmod/pythonmod.c index 28ce0eec4..3aa1c80f6 100644 --- a/pythonmod/pythonmod.c +++ b/pythonmod/pythonmod.c @@ -328,44 +328,12 @@ int pythonmod_init(struct module_env* env, int id) env->cfg->directory); PyRun_SimpleString(wdir); } - /* Check if sysconfig is there and use that instead of distutils; - * distutils.sysconfig is deprecated in Python 3.10. */ -#if PY_MAJOR_VERSION <= 2 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION <= 9) - /* For older versions, first try distutils.sysconfig because the - * sysconfig paths may contain wrong values, eg. on Debian10 for - * python 2.7 and 3.7. */ - if(PyRun_SimpleString("import distutils.sysconfig \n") < 0) { - log_info("pythonmod: module distutils.sysconfig not available; " - "falling back to sysconfig."); - if(PyRun_SimpleString("import sysconfig \n") < 0 - || PyRun_SimpleString("sys.path.append(" - "sysconfig.get_path('platlib')) \n") < 0) { - goto python_init_fail; - } - } else { - if(PyRun_SimpleString("sys.path.append(" - "distutils.sysconfig.get_python_lib(1,0)) \n") < 0) { - goto python_init_fail; - } + if(PyRun_SimpleString("import site\n") < 0) { + goto python_init_fail; } -#else - /* Python 3.10 and higher, check sysconfig first, - * distutils is deprecated. */ - if(PyRun_SimpleString("import sysconfig \n") < 0) { - log_info("pythonmod: module sysconfig not available; " - "falling back to distutils.sysconfig."); - if(PyRun_SimpleString("import distutils.sysconfig \n") < 0 - || PyRun_SimpleString("sys.path.append(" - "distutils.sysconfig.get_python_lib(1,0)) \n") < 0) { - goto python_init_fail; - } - } else { - if(PyRun_SimpleString("sys.path.append(" - "sysconfig.get_path('platlib')) \n") < 0) { - goto python_init_fail; - } + if(PyRun_SimpleString("sys.path.extend(site.getsitepackages())\n") < 0) { + goto python_init_fail; } -#endif if(PyRun_SimpleString("from unboundmodule import *\n") < 0) { goto python_init_fail; -- 2.39.5