原创文|Space9
Python文件打包成可安装、无需Python依赖的高效可执行exe程序
pypi 镜像使用帮助https://mirrors.tuna.tsinghua.edu.cn/help/pypi/
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyinstaller
pyinstaller -D -w -i "resources\logo.ico" AudioConverter.py Amusic.py --add-data "resources\7z.dll;." --add-data "resources\7z.exe;." --add-data "resources\aria2c.exe;." --add-data "resources\logo.ico;."
参数解释:
-D 创建一个包含可执行文件的单文件夹捆绑包(不推荐-F单文件形式,原因:单文件每次启动前需要解压操作,会拖慢启动速度)
-w 不显示控制台窗口,GUI可视化程序需要此项
-i 指定可执行文件的图标
-n 指定应用程序包的名称(默认值:第一个脚本的名称)
–add-data
其他参数可查阅官方文档https://pyinstaller.readthedocs.io/en/stable/
生成文件在dist目录下
出现运行异常兼容性问题,请尝试PyInstaller开发版本
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.tar.gz
高速访问GitHub
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple https://git.yumenaka.net/github.com/pyinstaller/pyinstaller/archive/develop.tar.gz
稳定版下载地址:https://jrsoftware.org/download.php/is.exe
测试版下载地址:https://jrsoftware.org/download.php/is-beta.exe
下载后桌面双击,即可开始安装
简体中文语言包下载地址:https://raw.github.com/jrsoftware/issrc/main/Files/Languages/Unofficial/ChineseSimplified.isl
高速访问GitHub:https://cdn.jsdelivr.net/gh/jrsoftware/issrc@main/Files/Languages/Unofficial/ChineseSimplified.isl
其他语言包:https://jrsoftware.org/files/istrans/
下载语言包之后,将语言包文件放入Inno Setup安装目录里的Languages目录中
使用向导生成打包安装程序的脚本,并保存
参考脚本
setup.iss
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define MyAppName "嗖音HOME"
#define MyAppVersion "3.2.0"
#define MyAppPublisher "独居者"
#define MyAppExeName "AudioConverter.exe"
[Setup]
; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{9DB7D8F0-D497-4AD8-A331-D3E74FD2C0DC}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
DefaultDirName={autopf}\{#MyAppName}
DisableProgramGroupPage=yes
; Remove the following line to run in administrative install mode (install for all users.)
PrivilegesRequired=lowest
OutputDir=.\outfile
OutputBaseFilename=嗖音HOME
SetupIconFile=.\resources\logo.ico
UninstallDisplayIcon=.\resources\logo.ico
Compression=lzma
SolidCompression=yes
WizardStyle=modern
[Languages]
Name: "chinesesimplified"; MessagesFile: "compiler:Languages\ChineseSimplified.isl"
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: checkablealone
[Files]
Source: ".\dist\AudioConverter\AudioConverter.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: ".\dist\AudioConverter\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
[Icons]
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent
[UninstallDelete]
Type: files; Name: "{app}\ffmpeg.exe"
Type: filesandordirs; Name: "{app}\WAV"
Type: files; Name: "{app}\cookie.json"
参数解释:
UninstallDisplayIcon=.\resources\logo.ico 设置卸载程序的图标
Flags: checkablealone 设置创建桌面快捷方式默认勾选状态
卸载删除文件或文件夹
[UninstallDelete]
Type: files; Name: “{app}\ffmpeg.exe”
Type: filesandordirs; Name: “{app}\WAV”
build.bat
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyinstaller
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple requests
pyinstaller -D -w -i "resources\logo.ico" AudioConverter.py Amusic.py --add-data "resources\7z.dll;." --add-data "resources\7z.exe;." --add-data "resources\aria2c.exe;." --add-data "resources\logo.ico;."
cd Inno Setup 6
iscc "..\setup.iss"
使用Github管理代码,并通过CI / CD工具轻松实现软件构建的自动化
您可以Star和Fork我的项目
https://github.com/space9bug/AudioConverter
本文仅为个人学习使用,不得用于任何商业用途,否则后果自负!如侵犯到您的权益,请及时通知我,我会及时处理。