@@ -37,6 +37,7 @@ TPythonVersion = record
37
37
DLLPath: string;
38
38
InstallPath: string;
39
39
PythonPath: string;
40
+ function Is_venv : Boolean;
40
41
procedure AssignTo (PythonEngine: TPersistent);
41
42
property PythonExecutable: string read GetPythonExecutable;
42
43
property DLLName: string read GetDLLName;
@@ -58,6 +59,8 @@ TPythonVersion = record
58
59
59
60
60
61
{ $IFDEF MSWINDOWS}
62
+ (* Checks whether an executable was compiled for X64 *)
63
+ function IsEXEx64 (const EXEName: string): Boolean;
61
64
(* Checks whether a DLL was compiled for X64 *)
62
65
function Isx64 (const FileName: string): Boolean;
63
66
(* Checks whether a Python version is registered and returns the related info *)
@@ -110,7 +113,8 @@ function TPythonVersion.ExpectedArchitecture: string;
110
113
111
114
procedure TPythonVersion.AssignTo (PythonEngine: TPersistent);
112
115
begin
113
- if PythonEngine is TPythonEngine then begin
116
+ if PythonEngine is TPythonEngine then
117
+ begin
114
118
TPythonEngine(PythonEngine).UseLastKnownVersion := False;
115
119
TPythonEngine(PythonEngine).RegVersion := SysVersion;
116
120
TPythonEngine(PythonEngine).DllName := DLLName;
@@ -177,6 +181,16 @@ function TPythonVersion.GetSysArchitecture: string;
177
181
Result := ' Unknown' ;
178
182
end ;
179
183
184
+ function TPythonVersion.Is_venv : Boolean;
185
+ {
186
+ Check weather this is python venv folder introduced in python 3.5
187
+ Note: venv is different from virtualenv
188
+ }
189
+ begin
190
+ Result := not IsRegistered and (InstallPath <> DLLPath) and
191
+ FileExists(IncludeTrailingPathDelimiter(InstallPath) + ' pyvenv.cfg' );
192
+ end ;
193
+
180
194
function CompareVersions (A, B : String) : Integer;
181
195
182
196
function GetNextNumber (var Version: string): Integer;
@@ -220,6 +234,15 @@ function CompareVersions(A, B : String) : Integer;
220
234
end ;
221
235
222
236
{ $IFDEF MSWINDOWS}
237
+ function IsEXEx64 (const EXEName: string): Boolean;
238
+ var
239
+ BinaryType: DWORD;
240
+ begin
241
+ Result := FileExists(EXEName) and
242
+ GetBinaryType(PChar(ExeName), Binarytype) and
243
+ (BinaryType = SCS_64BIT_BINARY);
244
+ end ;
245
+
223
246
function Isx64 (const FileName: string): Boolean;
224
247
var
225
248
Strm : TFileStream;
@@ -374,7 +397,7 @@ function PythonVersionFromPath(const Path: string; out PythonVersion: TPythonVer
374
397
DLLFileName: string;
375
398
begin
376
399
Result := ' ' ;
377
- Handle := FindFirstFile(PWideChar(Path +' \python??.dll' ), FindFileData);
400
+ Handle := FindFirstFile(PWideChar(APath +' \python??.dll' ), FindFileData);
378
401
if Handle = INVALID_HANDLE_VALUE then Exit; // not python dll
379
402
DLLFileName:= FindFileData.cFileName;
380
403
// skip if python3.dll was found
@@ -408,7 +431,7 @@ function PythonVersionFromPath(const Path: string; out PythonVersion: TPythonVer
408
431
409
432
// check if same platform
410
433
try
411
- if { $IFDEF CPUX64} not { $ENDIF} Isx64 (DLLPath+' \' +DLLFileName ) then Exit;
434
+ if { $IFDEF CPUX64} not { $ENDIF} IsEXEx64 (DLLPath+' \python.exe ' ) then Exit;
412
435
except
413
436
Exit;
414
437
end ;
0 commit comments