Skip to content

Commit a20b191

Browse files
committed
Workaround for python/cpython#100171
1 parent a345a86 commit a20b191

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

Source/PythonEngine.pas

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4473,6 +4473,7 @@ procedure TPythonEngine.Initialize;
44734473

44744474
var
44754475
i : Integer;
4476+
WorkAround: AnsiString;
44764477
begin
44774478
if Assigned(gPythonEngine) then
44784479
raise Exception.Create('There is already one instance of TPythonEngine running' );
@@ -4510,8 +4511,27 @@ procedure TPythonEngine.Initialize;
45104511
with Clients[i] do
45114512
if not Initialized then
45124513
Initialize;
4514+
4515+
// WorkAround for https://github.com/python/cpython/issues/100171
4516+
if (MajorVersion = 3) and (MinorVersion >= 11) then
4517+
begin
4518+
WorkAround :=
4519+
'import sys'#13#10 + //0
4520+
'if sys.version_info > (3,11,0):'#13#10 + //1
4521+
' import os'#13#10 + //2
4522+
''#13#10 + //3
4523+
' dllpath = os.path.join(sys.prefix, ''DLLs'')'#13#10 + //4
4524+
' if dllpath not in sys.path:'#13#10 + //5
4525+
' sys.path.insert(3, dllpath)'#13#10 + //6
4526+
''#13#10 + //7
4527+
' del dllpath'#13#10 + //8
4528+
' del os'#13#10 + //9
4529+
'del sys'#13#10; //10
4530+
ExecString(WorkAround);
4531+
end;
4532+
45134533
if InitScript.Count > 0 then
4514-
ExecStrings( InitScript );
4534+
ExecStrings(InitScript);
45154535
if Assigned(FOnAfterInit) then
45164536
FOnAfterInit(Self);
45174537
end;

0 commit comments

Comments
 (0)