@@ -1010,8 +1010,8 @@ PyConfig = record
1010
1010
ConfigOffests: TConfigOffsets =
1011
1011
{ $IFDEF MSWINDOWS}
1012
1012
{ $IFDEF CPU64BITS}
1013
- ((8 , 80 , 88 , 144 , 156 , 160 , 164 , 172 , 216 , 104 , 232 , 240 , 248 , 264 ),
1014
- (8 , 80 , 88 , 144 , 156 , 160 , 164 , 172 , 216 , 104 , 232 , 240 , 248 , 264 ),
1013
+ ((8 , 80 , 88 , 144 , 156 , 160 , 164 , 172 , 224 , 104 , 240 , 248 , 256 , 272 ),
1014
+ (8 , 80 , 88 , 144 , 156 , 160 , 164 , 172 , 224 , 104 , 240 , 248 , 256 , 272 ),
1015
1015
(8 , 80 , 104 , 152 , 168 , 172 , 176 , 184 , 232 , 240 , 256 , 272 , 280 , 296 ),
1016
1016
(8 , 96 , 120 , 168 , 184 , 188 , 192 , 200 , 264 , 272 , 288 , 304 , 312 , 336 ),
1017
1017
(8 , 96 , 120 , 168 , 184 , 188 , 192 , 200 , 268 , 272 , 288 , 304 , 312 , 336 ),
@@ -3036,6 +3036,8 @@ implementation
3036
3036
SPyConvertionError = ' Conversion Error: %s expects a %s Python object' ;
3037
3037
SPyExcStopIteration = ' Stop Iteration' ;
3038
3038
SPyExcSystemError = ' Unhandled SystemExit exception. Code: %s' ;
3039
+ SPyInitFailed = ' Python initialization failed: %s' ;
3040
+ SPyInitFailedUnknown = ' Unknown initialization error' ;
3039
3041
3040
3042
(* ******************************************************)
3041
3043
(* * **)
@@ -4720,6 +4722,8 @@ procedure TPythonEngine.Initialize;
4720
4722
var
4721
4723
i : Integer;
4722
4724
Config: PyConfig;
4725
+ Status: PyStatus;
4726
+ ErrMsg: string;
4723
4727
begin
4724
4728
if Assigned(gPythonEngine) then
4725
4729
raise Exception.Create(' There is already one instance of TPythonEngine running' );
@@ -4764,15 +4768,30 @@ procedure TPythonEngine.Initialize;
4764
4768
if Assigned(FOnConfigInit) then
4765
4769
FOnConfigInit(Self, Config);
4766
4770
4767
- Py_InitializeFromConfig(Config);
4771
+ Status := Py_InitializeFromConfig(Config);
4772
+ FInitialized := Py_IsInitialized() <> 0
4768
4773
finally
4769
4774
PyConfig_Clear(Config);
4770
4775
end ;
4771
4776
4772
- if Assigned(Py_IsInitialized) then
4773
- FInitialized := Py_IsInitialized() <> 0
4774
- else
4775
- FInitialized := True;
4777
+ if not FInitialized then
4778
+ begin
4779
+ if PyStatus_Exception(Status) then
4780
+ ErrMsg := Format(SPyInitFailed, [string(Status.err_msg)])
4781
+ else
4782
+ ErrMsg := Format(SPyInitFailed, [SPyInitFailedUnknown]);
4783
+ if FatalMsgDlg then
4784
+ { $IFDEF MSWINDOWS}
4785
+ MessageBox( GetActiveWindow, PChar(ErrMsg), ' Error' , MB_TASKMODAL or MB_ICONSTOP );
4786
+ { $ELSE}
4787
+ WriteLn(ErrOutput, ErrMsg);
4788
+ { $ENDIF}
4789
+ if FatalAbort then
4790
+ Quit
4791
+ else
4792
+ raise Exception.Create(ErrMsg);
4793
+ end ;
4794
+
4776
4795
InitSysPath;
4777
4796
if RedirectIO and Assigned(FIO) then
4778
4797
DoRedirectIO;
0 commit comments