Python NSIS安装桌面图标、开始菜单图标和中止/重试/忽略错误

Python NSIS安装桌面图标、开始菜单图标和中止/重试/忽略错误,python,pyqt,pyqt5,pyinstaller,nsis,Python,Pyqt,Pyqt5,Pyinstaller,Nsis,我最近制作了一个PyQt5应用程序,并使用pyinstaller构建了它。我已经制作了zip文件。现在我想使用NSIS获得一个安装程序。我转到示例页面,复制了以下代码“带开始菜单项的简单安装程序和卸载程序” 我试着阅读文档,但我不知道什么是安装目录,安装程序文件会在哪里,或者在windows上安装一些软件后会在程序文件中的什么位置。所有安装文件都在C:/Program files/[某些软件]中可见。是该文件夹吗?还有SetOutPath。我希望类似的行为,也就是说,安装程序应该有快捷方式图标在

我最近制作了一个PyQt5应用程序,并使用pyinstaller构建了它。我已经制作了zip文件。现在我想使用NSIS获得一个安装程序。我转到示例页面,复制了以下代码“带开始菜单项的简单安装程序和卸载程序”

我试着阅读文档,但我不知道什么是安装目录,安装程序文件会在哪里,或者在windows上安装一些软件后会在程序文件中的什么位置。所有安装文件都在C:/Program files/[某些软件]中可见。是该文件夹吗?还有SetOutPath。我希望类似的行为,也就是说,安装程序应该有快捷方式图标在桌面和开始菜单复选框。当用户运行安装程序时,它应该指向C:\ProgramFiles[应用程序名称]。当前,当使用“a.nsi”(包含复制代码的脚本)运行时,它会给我重试/忽略/中止错误。否则,当我尝试使用带zip文件的make安装程序选项时,我会得到一个很好的安装程序,但它没有放置桌面图标或开始菜单图标,它显示的默认安装目录是desktop

Name "Mailer"
# define name of installer
OutFile "Mailer-install.exe"
# For removing Start Menu shortcut in Windows 7
RequestExecutionLevel user

# define installation directory
InstallDir $PROGRAMFILES


# start default section
Section

    # set the installation directory as the destination for the following actions
    SetOutPath $INSTDIR
    File "Mailer.zip"
    # create the uninstaller
    WriteUninstaller "$INSTDIR\uninstall.exe"

    # create a shortcut named "new shortcut" in the start menu programs directory
    # point the new shortcut at the program uninstaller
    CreateShortCut "$SMPROGRAMS\new shortcut.lnk" "$INSTDIR\uninstall.exe"
SectionEnd

# uninstaller section start
Section "uninstall"

    # first, delete the uninstaller
    Delete "$INSTDIR\uninstall.exe"

    # second, remove the link from the start menu
    Delete "$SMPROGRAMS\new shortcut.lnk"

# uninstaller section end
SectionEnd

日志(如果需要)
您在示例脚本中做了致命更改,将
InstallDir
更改为
$PROGRAMFILES
,如果您不是高级管理员,则无法写入
$PROGRAMFILES

要为用户提供创建或不创建快捷方式的选项,请将其放在单独的
部分
中,然后添加一个组件页面:

Name "MyApp"
OutFile "MyAppSetup.exe"
Unicode True
RequestExecutionLevel Admin ; Request UAC elevation
InstallDir "$ProgramFiles\$(^Name)"

Page Components
Page Directory
Page InstFiles

Uninstpage UninstConfirm
Uninstpage InstFiles

!include LogicLib.nsh

!macro EnsureAdminRights
  UserInfo::GetAccountType
  Pop $0
  ${If} $0 != "admin" ; Require admin rights on WinNT4+
    MessageBox MB_IconStop "Administrator rights required!"
    SetErrorLevel 740 ; ERROR_ELEVATION_REQUIRED
    Quit
  ${EndIf}
!macroend

Function .onInit
  SetShellVarContext All
  !insertmacro EnsureAdminRights
FunctionEnd

Function un.onInit
  SetShellVarContext All
  !insertmacro EnsureAdminRights
FunctionEnd


Section "Program files (Required)"
  SectionIn Ro
  SetOutPath $InstDir ; Sets the output directory for File instructions
  WriteUninstaller "$InstDir\Uninst.exe"
  File "/oname=$InstDir\MyApp.exe" "${NSISDIR}\Bin\MakeLangId.exe" ; Pretend that we have a real application to install
SectionEnd

Section "Start Menu shortcut"
  CreateShortcut /NoWorkingDir "$SMPrograms\$(^Name).lnk" "$InstDir\MyApp.exe"
SectionEnd


Section -Uninstall
  Delete "$InstDir\MyApp.exe"
  Delete "$InstDir\Uninst.exe"
  RMDir "$InstDir"

  Delete "$SMPrograms\$(^Name).lnk"
SectionEnd

注意:这是的稍微修改版本。该脚本还将卸载程序注册到控制面板/设置应用程序中,您也应该在真正的安装程序中执行此操作。

此外,我还看到了有关stackoverflow的其他答案,但它们涉及函数和其他内容,目前我已经花了大量时间学习PyQT、pyinstaller。如果有人能帮我,我将不胜感激。此外,我对nsis语言了解不多,学习它还需要更多的时间,我真的很想快速发布该软件。我非常需要它。Microsoft指南规定,您不应在用户$Desktop上创建快捷方式,而应仅在“开始”菜单中创建快捷方式。快捷方式不应指向卸载程序。@Anders但是如果您现在使用任何软件,它在安装过程中经常显示复选框,允许用户放置桌面图标。StartMenu很好,但有些软件我经常使用,不想在搜索菜单中浪费几秒钟(输入和浪费时间用于选择、加载等)。我刚刚告诉你Microsoft指南是什么。如果你想要桌面选项,只需添加另一个部分并使用$desktop。谢谢你的回答,但当我问这个问题时,我不知道NSIS脚本生成器,但在谷歌搜索了一点(或很多)后,我发现了它,并打包了产品。尽管如此,您的代码肯定会提高我的技能,因为我可以理解脚本并使用它自定义安装程序,以提供更好的用户体验。感谢您的帮助。我选择程序文件,因为我想学习软件开发和所有软件只活在程序文件中。