@@ -1968,6 +1968,10 @@ TPythonInterface=class(TDynamicDll)
19681968 Py_GetCopyright : function : PAnsiChar; cdecl;
19691969 Py_GetExecPrefix : function : PAnsiChar; cdecl;
19701970 Py_GetPath : function : PAnsiChar; cdecl;
1971+ Py_SetPythonHome : procedure (home : PAnsiChar); cdecl;
1972+ Py_GetPythonHome : function : PAnsiChar; cdecl;
1973+ Py_SetPythonHome3000 : procedure (home : PWideChar); cdecl;
1974+ Py_GetPythonHome3000 : function : PWideChar; cdecl;
19711975 Py_GetPrefix : function : PAnsiChar; cdecl;
19721976 Py_GetProgramName : function : PAnsiChar; cdecl;
19731977
@@ -2187,6 +2191,8 @@ TPythonEngine = class(TPythonInterface)
21872191 FAutoFinalize: Boolean;
21882192 FProgramName: AnsiString;
21892193 FProgramNameW: UnicodeString;
2194+ FPythonHome: AnsiString;
2195+ FPythonHomeW: UnicodeString;
21902196 FInitThreads: Boolean;
21912197 FOnPathInitialization: TPathInitializationEvent;
21922198 FOnSysPathInit: TSysPathInitEvent;
@@ -2240,6 +2246,7 @@ TPythonEngine = class(TPythonInterface)
22402246 procedure Finalize ;
22412247 procedure Lock ;
22422248 procedure Unlock ;
2249+ procedure SetPythonHome (PythonHome: String);
22432250 function IsType (ob: PPyObject; obt: PPyTypeObject): Boolean;
22442251 function GetAttrString (obj: PPyObject; AName: PAnsiChar):PAnsiChar;
22452252 function CleanString (const s : AnsiString) : AnsiString;
@@ -4056,6 +4063,14 @@ procedure TPythonInterface.MapDll;
40564063 Py_GetCopyright :=Import (' Py_GetCopyright' );
40574064 Py_GetExecPrefix :=Import (' Py_GetExecPrefix' );
40584065 Py_GetPath :=Import (' Py_GetPath' );
4066+ if IsPython3000 then
4067+ Py_SetPythonHome3000 :=Import (' Py_SetPythonHome' )
4068+ else
4069+ Py_SetPythonHome :=Import (' Py_SetPythonHome' );
4070+ if IsPython3000 then
4071+ Py_GetPythonHome3000 :=Import (' Py_GetPythonHome' )
4072+ else
4073+ Py_GetPythonHome :=Import (' Py_GetPythonHome' );
40594074 Py_GetPrefix :=Import (' Py_GetPrefix' );
40604075 Py_GetProgramName :=Import (' Py_GetProgramName' );
40614076 PyParser_SimpleParseString :=Import (' PyParser_SimpleParseString' );
@@ -4850,6 +4865,12 @@ procedure TPythonEngine.Initialize;
48504865 end
48514866 end ;
48524867 AssignPyFlags;
4868+ if FPythonHomeW<>' ' then begin
4869+ if IsPython3000 then
4870+ Py_SetPythonHome3000(PChar(FPythonHomeW))
4871+ else
4872+ Py_SetPythonHome(PAnsiChar(FPythonHome));
4873+ end ;
48534874 Py_Initialize;
48544875 FInitialized := True;
48554876 FIORedirected := False;
@@ -5111,6 +5132,12 @@ procedure TPythonEngine.SetPyFlags(const Value: TPythonFlags);
51115132 end ; // of if
51125133end ;
51135134
5135+ procedure TPythonEngine.SetPythonHome (PythonHome: String);
5136+ begin
5137+ FPythonHomeW := PythonHome;
5138+ FPythonHome := UTF8Encode(PythonHome);
5139+ end ;
5140+
51145141function TPythonEngine.IsType (ob: PPyObject; obt: PPyTypeObject): Boolean;
51155142begin
51165143 result := ob^.ob_type = obt;
0 commit comments