@@ -1010,8 +1010,8 @@  PyConfig = record
10101010    ConfigOffests: TConfigOffsets =
10111011    { $IFDEF MSWINDOWS} 
10121012      { $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 ),
10151015       (8 , 80 , 104 , 152 , 168 , 172 , 176 , 184 , 232 , 240 , 256 , 272 , 280 , 296 ),
10161016       (8 , 96 , 120 , 168 , 184 , 188 , 192 , 200 , 264 , 272 , 288 , 304 , 312 , 336 ),
10171017       (8 , 96 , 120 , 168 , 184 , 188 , 192 , 200 , 268 , 272 , 288 , 304 , 312 , 336 ),
@@ -3036,6 +3036,8 @@ implementation
30363036SPyConvertionError = ' Conversion Error: %s expects a %s Python object' 
30373037SPyExcStopIteration = ' Stop Iteration' 
30383038SPyExcSystemError = ' Unhandled SystemExit exception. Code: %s' 
3039+ SPyInitFailed = ' Python initialization failed: %s' 
3040+ SPyInitFailedUnknown = ' Unknown initialization error' 
30393041
30403042(* ******************************************************) 
30413043(* *                                                   **) 
@@ -4720,6 +4722,8 @@ procedure TPythonEngine.Initialize;
47204722var 
47214723  i : Integer;
47224724  Config: PyConfig;
4725+   Status: PyStatus;
4726+   ErrMsg: string;
47234727begin 
47244728  if  Assigned(gPythonEngine) then 
47254729    raise Exception.Create(' There is already one instance of TPythonEngine running' 
@@ -4764,15 +4768,30 @@ procedure TPythonEngine.Initialize;
47644768      if  Assigned(FOnConfigInit) then 
47654769        FOnConfigInit(Self, Config);
47664770
4767-       Py_InitializeFromConfig(Config);
4771+       Status := Py_InitializeFromConfig(Config);
4772+       FInitialized := Py_IsInitialized() <> 0 
47684773    finally 
47694774      PyConfig_Clear(Config);
47704775    end ;
47714776
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' 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+ 
47764795    InitSysPath;
47774796    if  RedirectIO and  Assigned(FIO) then 
47784797      DoRedirectIO;
0 commit comments