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

穿精又带淫゛_ 提交于 2021-02-07 09:55:41

问题


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

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


回答1:


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

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

Solution

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;


来源:https://stackoverflow.com/questions/65792824/how-to-check-if-specific-python-version-is-installed-in-inno-setup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!