简体   繁体   English

如何检查 Inno Setup 中是否安装了特定的 Python 版本?

[英]How to check if specific Python version is installed in Inno Setup?

How can I write a setup script for Inno Setup Compiler that will install Python only if the right version is not available?我怎样才能为 Inno Setup Compiler 编写安装脚本,仅当正确的版本不可用时才安装 Python?

How do I check if a specific Python version eg Python 3.6.8, 32-bit , is installed?如何检查是否安装了特定的 Python 版本,例如Python 3.6.8, 32-bit

Method方法

The installation check can be done in the code section of setup script by using registry functions.安装检查可以使用注册表函数在安装脚本的代码部分完成。 Python installer creates registry keys in various locations, depending on the type of installation: Python 安装程序根据安装类型在不同位置创建注册表项:

  • HKEY_CURRENT_USER\Software\Python\PythonCore
  • HKEY_LOCAL_MACHINE\Software\Python\PythonCore
  • HKEY_CURRENT_USER\Software\Wow6432Node\Python\PythonCore
  • HKEY_LOCAL_MACHINE\Software\Wow6432Node\Python\PythonCore

The complete structure of Python registry organisation can be found in PEP 514 . Python 注册机构的完整结构可以在PEP 514中找到。

Solution解决方案

Use the following function to check if Python 3.6.8, 32 or 64 bit version is installed.使用以下 function 检查是否安装了 Python 3.6.8、32 或 64 位版本。 This function is not universal because Python registry organisation has changed over Python versions.此 function 不是通用的,因为 Python 注册表组织已更改为 Python 版本。 Please adapt to your needs and let us know if you find solutions for other versions.请适应您的需求,如果您找到其他版本的解决方案,请告诉我们。

[Code]
{Check existence of key in registry and check version string.
return true if Python is installed and version is correct}
function checkKey(regpart: integer; key: string; version: string) : Boolean;
var
  installedVersion: string;
begin
   Result :=
     { Check if key exists }
     RegKeyExists(regpart, Key) and
     { try to get version string }
     RegQueryStringValue(regpart, key, 'Version', installedVersion) and
     { check version string }
     (version = installedVersion);
end;

{ Return true if python 3.6.8 bit is not installed }
function python_3_6_8_is_not_installed() : Boolean;
var
  Key : string;
  Version: string;
begin
   { check registry }
   Key := 'Software\Python\PythonCore\3.6-32';
   Version := '3.6.8';
   Result :=
     { Check all user 32-bit installation}
     (not checkKey(HKLM32, Key, Version)) and
     { Check current user 32-bit installation}
     (not checkKey(HKCU32, Key, Version)) and
     { Check all user 64-bit installation}
     (not checkKey(HKLM64, Key, Version)) and
     { Check current user 64-bit installation}
     (not checkKey(HKCU64, Key, Version));
end;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM