Skip to content

Commit d69b064

Browse files
committed
port VenvPythonExe prop from P4D
1 parent 475b62e commit d69b064

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

python4lazarus/PythonEngine.pas

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,6 +1718,7 @@ TPythonType = class; //forward declaration
17181718
{$IFEND}
17191719
TPythonEngine = class(TPythonInterface)
17201720
private
1721+
FVenvPythonExe: string;
17211722
FInitScript: TStrings;
17221723
FIO: TPythonInputOutput;
17231724
FRedirectIO: Boolean;
@@ -1862,6 +1863,7 @@ TPythonEngine = class(TPythonInterface)
18621863
property ProgramName: UnicodeString read FProgramName write SetProgramName;
18631864
published
18641865
property AutoFinalize: Boolean read FAutoFinalize write FAutoFinalize default True;
1866+
property VenvPythonExe: string read FVenvPythonExe write FVenvPythonExe;
18651867
property DatetimeConversionMode: TDatetimeConversionMode read FDatetimeConversionMode write FDatetimeConversionMode default DEFAULT_DATETIME_CONVERSION_MODE;
18661868
property InitScript: TStrings read FInitScript write SetInitScript;
18671869
property InitThreads: Boolean read FInitThreads write SetInitThreads default False;
@@ -4064,7 +4066,19 @@ procedure TPythonEngine.Initialize;
40644066
procedure InitSysPath;
40654067
var
40664068
_path : PPyObject;
4069+
const Script =
4070+
'import sys' + sLineBreak +
4071+
'sys.executable = r"%s"' + sLineBreak +
4072+
'path = sys.path' + sLineBreak +
4073+
'for i in range(len(path)-1, -1, -1):' + sLineBreak +
4074+
' if path[i].find("site-packages") > 0:' + sLineBreak +
4075+
' path.pop(i)' + sLineBreak +
4076+
'import site' + sLineBreak +
4077+
'site.main()' + sLineBreak +
4078+
'del sys, path, i, site';
40674079
begin
4080+
if VenvPythonExe <> '' then
4081+
ExecString(AnsiString(Format(Script, [VenvPythonExe])));
40684082
_path := PySys_GetObject('path');
40694083
if Assigned(FOnSysPathInit) then
40704084
FOnSysPathInit(Self, _path);

0 commit comments

Comments
 (0)