aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside-tools
diff options
context:
space:
mode:
authorShyamnath Premnadh <Shyamnath.Premnadh@qt.io>2024-01-03 10:09:44 +0100
committerShyamnath Premnadh <Shyamnath.Premnadh@qt.io>2024-01-05 21:29:27 +0100
commit9e6e4e8d21758539b3a9c1aef763d310f91963f1 (patch)
tree18a6806a939b4f950f00339200d53e0a9f0bb159 /sources/pyside-tools
parent743b4c3ec596c0c6e2212a0f83e9990809f19367 (diff)
Fix pyside6-designer crash with pyenv on Unix
- With pyenv installed Python, we need to explicitly add the full Python library path to LD_PRELOAD(Linux) and DYLD_INSERT_LIBRARIES(macOS). Otherwise, these libraries are searched in the default search paths of ld and dyld, and it won't be able to find them. - for macOS, the python installed with pyenv won't be a framework build unless explicitly specified. Thus we use the same approach for linux by looking for the Python library inside the path in `LIBDIR`. In the case of a framework build with pyenv, 'PYTHONFRAMEWORKPREFIX' will not be empty and hence no explcit changes are required. Fixes: PYSIDE-2568 Pick-to: 6.2 6.5 6.6 Change-Id: I94815b721acb85fa0b7f28d1bbb00a49717120c3 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/pyside-tools')
-rw-r--r--sources/pyside-tools/pyside_tool.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/sources/pyside-tools/pyside_tool.py b/sources/pyside-tools/pyside_tool.py
index 280c9ec3b..84bd61986 100644
--- a/sources/pyside-tools/pyside_tool.py
+++ b/sources/pyside-tools/pyside_tool.py
@@ -15,6 +15,17 @@ import PySide6 as ref_mod
VIRTUAL_ENV = "VIRTUAL_ENV"
+def is_pyenv_python():
+ pyenv_root = os.environ.get("PYENV_ROOT")
+
+ if pyenv_root:
+ resolved_exe = Path(sys.executable).resolve()
+ if str(resolved_exe).startswith(pyenv_root):
+ return True
+
+ return False
+
+
def is_virtual_env():
return sys.prefix != sys.base_prefix
@@ -147,11 +158,23 @@ def designer():
# Determine library name (examples/utils/pyside_config.py)
version = f'{major_version}.{minor_version}'
library_name = f'libpython{version}{sys.abiflags}.so'
+ if is_pyenv_python():
+ library_name = str(Path(sysconfig.get_config_var('LIBDIR')) / library_name)
os.environ['LD_PRELOAD'] = library_name
elif sys.platform == 'darwin':
library_name = sysconfig.get_config_var("LDLIBRARY")
framework_prefix = sysconfig.get_config_var("PYTHONFRAMEWORKPREFIX")
- lib_path = os.fspath(Path(framework_prefix) / library_name)
+ lib_path = None
+ if framework_prefix:
+ lib_path = os.fspath(Path(framework_prefix) / library_name)
+ elif is_pyenv_python():
+ lib_path = str(Path(sysconfig.get_config_var('LIBDIR')) / library_name)
+ else:
+ # ideally this should never be reached because the system Python and Python installed
+ # from python.org are all framework builds
+ print("Unable to find Python library directory. Use a framework build of Python.",
+ file=sys.stderr)
+ sys.exit(0)
os.environ['DYLD_INSERT_LIBRARIES'] = lib_path
elif sys.platform == 'win32':
# Find Python DLLs from the base installation