如何检查Inno Setup中是否安装了特定的Python版本? [英] How to check if specific Python version is installed in Inno Setup?

查看:77
本文介绍了如何检查Inno Setup中是否安装了特定的Python版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为Inno Setup Compiler编写安装脚本,该脚本仅在没有正确版本的情况下才安装Python?

How can I write a setup script for Inno Setup Compiler that will install Python only if the right version is not available?

如何检查特定的Python版本,例如已安装 Python 3.6.8(32位)?

How do I check if a specific Python version e.g. Python 3.6.8, 32-bit, is installed?

推荐答案

方法

可以使用注册表功能在安装脚本的代码部分中完成安装检查.Python安装程序会在不同位置创建注册表项,具体取决于安装类型:

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:

  • 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

Python注册表组织的完整结构可以在 PEP 514 <中找到/a>.

The complete structure of Python registry organisation can be found in PEP 514.

使用以下函数检查是否安装了Python 3.6.8、32或64位版本.此功能不是通用的,因为Python注册表组织已更改了Python版本.请适应您的需求,如果您找到其他版本的解决方案,请告诉我们.

Use the following function to check if Python 3.6.8, 32 or 64 bit version is installed. This function is not universal because Python registry organisation has changed over Python versions. 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;

这篇关于如何检查Inno Setup中是否安装了特定的Python版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆