@@ -1968,6 +1968,10 @@ TPythonInterface=class(TDynamicDll)
1968
1968
Py_GetCopyright : function : PAnsiChar; cdecl;
1969
1969
Py_GetExecPrefix : function : PAnsiChar; cdecl;
1970
1970
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;
1971
1975
Py_GetPrefix : function : PAnsiChar; cdecl;
1972
1976
Py_GetProgramName : function : PAnsiChar; cdecl;
1973
1977
@@ -2187,6 +2191,8 @@ TPythonEngine = class(TPythonInterface)
2187
2191
FAutoFinalize: Boolean;
2188
2192
FProgramName: AnsiString;
2189
2193
FProgramNameW: UnicodeString;
2194
+ FPythonHome: AnsiString;
2195
+ FPythonHomeW: UnicodeString;
2190
2196
FInitThreads: Boolean;
2191
2197
FOnPathInitialization: TPathInitializationEvent;
2192
2198
FOnSysPathInit: TSysPathInitEvent;
@@ -2240,6 +2246,7 @@ TPythonEngine = class(TPythonInterface)
2240
2246
procedure Finalize ;
2241
2247
procedure Lock ;
2242
2248
procedure Unlock ;
2249
+ procedure SetPythonHome (PythonHome: String);
2243
2250
function IsType (ob: PPyObject; obt: PPyTypeObject): Boolean;
2244
2251
function GetAttrString (obj: PPyObject; AName: PAnsiChar):PAnsiChar;
2245
2252
function CleanString (const s : AnsiString) : AnsiString;
@@ -4056,6 +4063,14 @@ procedure TPythonInterface.MapDll;
4056
4063
Py_GetCopyright :=Import (' Py_GetCopyright' );
4057
4064
Py_GetExecPrefix :=Import (' Py_GetExecPrefix' );
4058
4065
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' );
4059
4074
Py_GetPrefix :=Import (' Py_GetPrefix' );
4060
4075
Py_GetProgramName :=Import (' Py_GetProgramName' );
4061
4076
PyParser_SimpleParseString :=Import (' PyParser_SimpleParseString' );
@@ -4850,6 +4865,12 @@ procedure TPythonEngine.Initialize;
4850
4865
end
4851
4866
end ;
4852
4867
AssignPyFlags;
4868
+ if FPythonHomeW<>' ' then begin
4869
+ if IsPython3000 then
4870
+ Py_SetPythonHome3000(PChar(FPythonHomeW))
4871
+ else
4872
+ Py_SetPythonHome(PAnsiChar(FPythonHome));
4873
+ end ;
4853
4874
Py_Initialize;
4854
4875
FInitialized := True;
4855
4876
FIORedirected := False;
@@ -5111,6 +5132,12 @@ procedure TPythonEngine.SetPyFlags(const Value: TPythonFlags);
5111
5132
end ; // of if
5112
5133
end ;
5113
5134
5135
+ procedure TPythonEngine.SetPythonHome (PythonHome: String);
5136
+ begin
5137
+ FPythonHomeW := PythonHome;
5138
+ FPythonHome := UTF8Encode(PythonHome);
5139
+ end ;
5140
+
5114
5141
function TPythonEngine.IsType (ob: PPyObject; obt: PPyTypeObject): Boolean;
5115
5142
begin
5116
5143
result := ob^.ob_type = obt;
0 commit comments