Skip to content

Commit 89cb161

Browse files
authored
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.
1 parent 9c3be6b commit 89cb161

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

plugins/python/uwsgiplugin.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ def get_python_version():
4545
if 'UWSGI_PYTHON_NOLIB' not in os.environ:
4646
LIBS = sysconfig.get_config_var('LIBS').split() + sysconfig.get_config_var('SYSLIBS').split()
4747
# check if it is a non-shared build (but please, add --enable-shared to your python's ./configure script)
48-
if not sysconfig.get_config_var('Py_ENABLE_SHARED'):
48+
use_static_lib = not sysconfig.get_config_var('Py_ENABLE_SHARED')
49+
if use_static_lib:
4950
libdir = sysconfig.get_config_var('LIBPL')
5051
# libdir does not exists, try to get it from the venv
5152
version = get_python_version()
@@ -75,13 +76,17 @@ def get_python_version():
7576
libpath = '%s/%s' % (libdir, sysconfig.get_config_var('LIBRARY'))
7677
if not os.path.exists(libpath):
7778
libpath = '%s/libpython%s.a' % (libdir, version)
78-
LIBS.append(libpath)
79-
# hack for messy linkers/compilers
80-
if '-lutil' in LIBS:
81-
LIBS.append('-lutil')
82-
if '-lrt' in LIBS:
83-
LIBS.append('-lrt')
84-
else:
79+
80+
if os.path.exists(libpath):
81+
LIBS.append(libpath)
82+
# hack for messy linkers/compilers
83+
if '-lutil' in LIBS:
84+
LIBS.append('-lutil')
85+
if '-lrt' in LIBS:
86+
LIBS.append('-lrt')
87+
else:
88+
use_static_lib = False
89+
if not use_static_lib:
8590
try:
8691
libdir = sysconfig.get_config_var('LIBDIR')
8792
except Exception:

0 commit comments

Comments
 (0)