Inno Setup代码安装Python

5
我有一个inno安装代码,它安装了Python。它可以正常运行,并且我得到了包含Python的setup.exe文件。但是,当我尝试使用该安装文件安装Python时,无法正常工作。这是因为设置文件正在查找文件部分中指定的Python文件吗?如果是这样,我该如何更改代码以使用setup.exe中的Python?此外,每次安装设置时,设置都会创建一个默认应用程序。我已尝试使用DisableDirPage=yes属性,但它没有起作用。有人可以提供一些解决方案吗?
             #define MyAppName "My Program"
             #define MyAppVersion "1.5"



                    [Setup]
           AppId={{BD59E856-F194-4E05-A93B-89089F3E3E9D}
           AppName={#MyAppName}
           AppVersion={#MyAppVersion}
          ;AppVerName={#MyAppName} {#MyAppVersion}
          ;AppPublisher={#MyAppPublisher}
          ;AppPublisherURL={#MyAppURL}
          ;AppSupportURL={#MyAppURL}
           ;AppUpdatesURL={#MyAppURL}
           DefaultDirName={pf}\{#MyAppName}
           DefaultGroupName={#MyAppName}
           OutputBaseFilename=setup
           Compression=lzma
           SolidCompression=yes
           DisableDirPage=yes


          [Files]
             Source: "H:\python-2.7.5.msi"; DestDir: "{app}"; Flags: ignoreversion




            [code]
             #define MinJRE "1.6"
            #define WebJRE "H:\python-2.7.5.msi"

           function InitializeSetup(): Boolean;
           var
          ErrorCode: Integer;
         PythonInstalled : Boolean;
          Result1 : Boolean;
          begin
              PythonInstalled :=                      RegKeyExists(HKLM,'SOFTWARE\Wow6432Node\Python\PythonCore\2.7\InstallPath');
          if PythonInstalled then
            begin
          MsgBox('installed', mbInformation, MB_OK);
           end
                else
            begin

           Result1 := MsgBox('2222222222222222This tool requires python Runtime Environment  to run.  Do you want to install it now?',
            mbConfirmation, MB_YESNO) = idYes;
          if Result1 = false then
             begin    
             Result:=false;
             end 
         else
            begin

             MsgBox('not installed', mbInformation, MB_OK);
              Result:=true;
              ShellExec('',
               '{#WebJRE}',
              '','',SW_SHOWNORMAL,ewNoWait,ErrorCode);
             end;
                  end;
                end;

1
你正在调用ShellExec,传递了#WebJRE常量,该常量位于你的H:驱动器上的某个位置。将[Files]条目更改为Source: "H:\python-2.7.5.msi"; Flags: dontcopy,因为我认为你不想将该安装程序复制到目标应用程序文件夹中。在调用ShellExec之前的InitializeSetup事件方法中使用ExtractTemporaryFile('python-2.7.5.msi'),然后从{tmp}\python-2.7.5.msi路径执行它。此外,你应该改进你的代码格式和添加错误处理。 - TLama
@TLama,我已经进行了指定的更改并编译了代码。但是现在,在执行安装程序时,它只是将文件复制到所选文件夹(例如C:\ Program Files(x86)\ My Program),其中包含Python安装程序,并且ShellExec未能正常工作。您能否请指导我我的代码出了什么问题? - dileepVikram
我的猜测是,当您调用ShellExec时,您没有使用ExpandConstant('{tmp}\python-2.7.5.msi')扩展常量。在调用该函数时,必须扩展传递给该函数的路径。 - TLama
1个回答

5

根据Tlama的建议,对您的脚本进行了一些更改。在我的端口工作良好,更改了文件部分条目并使用Exec而不是ShellExec...

将python-2.7.5.amd64.msi替换为python-2.7.5.msi,并将D:\替换为H:\

#define MyAppName "My Program"
#define MyAppVersion "1.5"

[Setup]
AppId={{BD59E856-F194-4E05-A93B-89089F3E3E9D}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppName}
OutputBaseFilename=setup
Compression=lzma
SolidCompression=yes
DisableDirPage=yes

[Files]
Source: "D:\python-2.7.5.amd64.msi"; Flags: dontcopy

[code]
#define MinJRE "1.6"

function InitializeSetup: Boolean;
var
  ErrorCode: Integer;
  PythonInstalled: Boolean;
  Result1: Boolean;
  WebJRE: string;
begin
  PythonInstalled := RegKeyExists(HKLM, 'SOFTWARE\Wow6432Node\Python\PythonCore\2.7\InstallPath');
  if PythonInstalled then
  begin
    MsgBox('installed', mbInformation, MB_OK);
  end
  else
  begin
    Result1 := MsgBox('This tool requires python Runtime Environment  to run.  Do you want to install it now ?', mbConfirmation, MB_YESNO) = IDYES;
    if not Result1 then
    begin    
      Result := False;
    end 
    else
    begin
      MsgBox('not installed', mbInformation, MB_OK);
      Result := True;

      ExtractTemporaryFile('python-2.7.5.amd64.msi')
      WebJRE:='"'+Expandconstant('{tmp}\python-2.7.5.amd64.msi')+'"'
      Exec('cmd.exe ','/c'+WebJRE,'', SW_HIDE,ewWaituntilterminated, Errorcode);
    end;
  end;
end;

1
完全没有必要使用cmd.exe,使用ShellExec会非常相似。 - TLama
@TLama,我喜欢您的Edit。是的,ShellExec也很好用。我们不用cmd.exe也可以做到这一点。但我更喜欢Exec+cmd.exe。这就是为什么我在这里使用它的原因。非常感谢您的编辑和信息。 - Gangadhar

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接