Skip to content

Commit

Permalink
Fix pip install static library not found errors for conda (#2683)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
shaform authored Oct 26, 2024
1 parent 9c3be6b commit 89cb161
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions plugins/python/uwsgiplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def get_python_version():
if 'UWSGI_PYTHON_NOLIB' not 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()
Expand Down Expand Up @@ -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 Exception:
Expand Down

0 comments on commit 89cb161

Please sign in to comment.