From a45de8ce2f8937a6f7f22db27a532447b6745774 Mon Sep 17 00:00:00 2001 From: Yong-Siang Shih Date: Sat, 26 Oct 2024 05:39:02 -0400 Subject: [PATCH] Fix pip install static library not found errors for conda (#2683) Under certain circumstances Py_ENABLE_SHARED would be False but the static library cannot be found. For example, if you use conda environments or if you use specific versions of MacOS #2109, #2270. pip install would fail in such a situation. In this PR, we adjust the configurations so that the installation script would attempt to use shared library instead of the static one if no static library is found. This fixes pip install for Python 3.10.15 | packaged by conda-forge. It's not clear if this would fix the MacOS problems mentioned in the above issues though, as I am unable to verify those problems. --- plugins/python/uwsgiplugin.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/plugins/python/uwsgiplugin.py b/plugins/python/uwsgiplugin.py index b4e20c3e2..aa40e20e7 100644 --- a/plugins/python/uwsgiplugin.py +++ b/plugins/python/uwsgiplugin.py @@ -45,7 +45,8 @@ def get_python_version(): if not 'UWSGI_PYTHON_NOLIB' in os.environ: LIBS = sysconfig.get_config_var('LIBS').split() + sysconfig.get_config_var('SYSLIBS').split() # check if it is a non-shared build (but please, add --enable-shared to your python's ./configure script) - if not sysconfig.get_config_var('Py_ENABLE_SHARED'): + use_static_lib = not sysconfig.get_config_var('Py_ENABLE_SHARED') + if use_static_lib: libdir = sysconfig.get_config_var('LIBPL') # libdir does not exists, try to get it from the venv version = get_python_version() @@ -75,13 +76,17 @@ def get_python_version(): libpath = '%s/%s' % (libdir, sysconfig.get_config_var('LIBRARY')) if not os.path.exists(libpath): libpath = '%s/libpython%s.a' % (libdir, version) - LIBS.append(libpath) - # hack for messy linkers/compilers - if '-lutil' in LIBS: - LIBS.append('-lutil') - if '-lrt' in LIBS: - LIBS.append('-lrt') - else: + + if os.path.exists(libpath): + LIBS.append(libpath) + # hack for messy linkers/compilers + if '-lutil' in LIBS: + LIBS.append('-lutil') + if '-lrt' in LIBS: + LIBS.append('-lrt') + else: + use_static_lib = False + if not use_static_lib: try: libdir = sysconfig.get_config_var('LIBDIR') except: