From 8f866331fc336d4b836ebd15663f22fd3b6a8c10 Mon Sep 17 00:00:00 2001 From: Idan Miara Date: Thu, 4 Feb 2021 20:33:10 +0200 Subject: [PATCH] PythonVersions.pas - PythonVersionFromPath.FindPythonDLL improved - search only for supported versions of Python (and also support >=v3.10) --- Source/PythonVersions.pas | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/Source/PythonVersions.pas b/Source/PythonVersions.pas index b31a3d60..8990365b 100644 --- a/Source/PythonVersions.pas +++ b/Source/PythonVersions.pas @@ -435,21 +435,18 @@ function PythonVersionFromPath(const Path: string; out PythonVersion: TPythonVer function FindPythonDLL(APath : string): string; Var - FindFileData: TWIN32FindData; - Handle : THandle; DLLFileName: string; + I: integer; begin Result := ''; - Handle := FindFirstFile(PWideChar(APath+'\python??.dll'), FindFileData); - if Handle = INVALID_HANDLE_VALUE then Exit; // not python dll - DLLFileName:= FindFileData.cFileName; - // skip if python3.dll was found - if Length(DLLFileName) <> 12 then FindNextFile(Handle, FindFileData); - if Handle = INVALID_HANDLE_VALUE then Exit; - Windows.FindClose(Handle); - DLLFileName:= FindFileData.cFileName; - if Length(DLLFileName) = 12 then - Result := DLLFileName; + APath := IncludeTrailingPathDelimiter(APath); + for I := High(PYTHON_KNOWN_VERSIONS) downto COMPILED_FOR_PYTHON_VERSION_INDEX do begin + DLLFileName := PYTHON_KNOWN_VERSIONS[I].DLLName; + if FileExists(APath+DLLFileName) then begin + Result := DLLFileName; + exit; + end; + end; end; function GetVenvBasePrefix(InstallPath: string): string;