File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed
Libs/Scripting/Python/Core/Python Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -5,11 +5,21 @@ its namespace."""
55
66__kits_to_load = [ @CTK_PYTHON_WRAPPED_LIBRARIES@ ]
77
8+ import os
9+ import sys
10+ _standalone_python = "python" in str.lower(os.path.split(sys.executable)[-1])
11+
812# Set to True when debugging
913_CTK_VERBOSE_IMPORT = False
1014
1115kits = []
1216for kit in __kits_to_load:
17+ # Since importing a PythonQt-based module outside of a Qt application
18+ # leads to a segfault, skip the import if it happens in a standalone
19+ # python interpreter.
20+ # See https://github.com/commontk/CTK/pull/520
21+ if _standalone_python:
22+ continue
1323 try:
1424 exec("from CTK%sPythonQt import *" % kit)
1525 kits.append(kit)
@@ -103,6 +113,6 @@ if _lib == 'Widgets':
103113 decorates_ctkWorkflowWidgetStep_initialize_method()
104114
105115# Removing things the user shouldn't have to see.
106- del __kits_to_load, _lib, _CTK_VERBOSE_IMPORT
116+ del __kits_to_load, _lib, _standalone_python, _CTK_VERBOSE_IMPORT
107117del add_methodclass_to_ctkWorkflowStep_or_ctkWorkflowWidgetStep
108118del add_methodclass_to_ctkWorkflowWidgetStep, decorates_ctkWorkflowWidgetStep_initialize_method
Original file line number Diff line number Diff line change @@ -5,18 +5,28 @@ its namespace."""
55
66__kits_to_load = [ @QT_PYTHON_WRAPPED_LIBRARIES@ ]
77
8+ import os
9+ import sys
10+ _standalone_python = "python" in str.lower(os.path.split(sys.executable)[-1])
11+
812# Set to True when debugging
913_CTK_VERBOSE_IMPORT = False
1014
1115for kit in __kits_to_load:
16+ # Since importing a PythonQt-based module outside of a Qt application
17+ # leads to a segfault, skip the import if it happens in a standalone
18+ # python interpreter.
19+ # See https://github.com/commontk/CTK/pull/520
20+ if _standalone_python:
21+ continue
1222 try:
1323 exec("from PythonQt.Qt%s import *" % kit)
1424 except ImportError as detail:
1525 if _CTK_VERBOSE_IMPORT:
1626 print(detail)
1727
18- if "QObject" not in locals():
28+ if "QObject" not in locals() and not _standalone_python :
1929 from PythonQt.private import QObject
2030
2131# Removing things the user shouldn't have to see.
22- del __kits_to_load, _CTK_VERBOSE_IMPORT
32+ del __kits_to_load, _standalone_python, _CTK_VERBOSE_IMPORT
You can’t perform that action at this time.
0 commit comments