手把手教你把pyqt软件打包成exe,ISCC配置文件参考代码编写,WinRAR压缩成升级包.zip脚本,干货满满【强烈建议收藏】

该文介绍了如何使用InnoSetupCompiler(ISCC)和Nuitka工具将Python应用程序打包成Windows可执行文件(exe)。首先展示了ISCC的配置脚本,包括设置应用信息、安装路径等。接着,详细说明了Nuitka的使用,包括指定图标、独立编译、包含数据文件等参数。最后,提到了打包过程,包括复制文件、创建ZIP、生成MD5校验值以及使用ISCC创建安装包。
摘要由CSDN通过智能技术生成

ISCC配置

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "软件名"
#define MyAppVersion "2.0.0"
#define MyAppPublisher "niyuming, Inc."
#define MyAppURL "https://member.niyuming.com/#/login"
#define MyAppExeName "upexe.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={{DCBC5E2E-91C7-45F1-8843-15DE4E0E0F2A}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName=D:\Program Files\{#MyAppName}
DisableProgramGroupPage=yes
LicenseFile=E:\软件名打包记录\软件名资料\license.txt
PrivilegesRequired=admin
; Uncomment the following line to run in non administrative install mode (install for current user only.)
;PrivilegesRequired=lowest
;OutputDir=C:\Users\NING MEI\Desktop
OutputDir=output
OutputBaseFilename=新版本软件名安装包
SetupIconFile=F:\code.fy.com\myNewStart\new_start.dist\cate\icons\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: "F:\code.fy.com\myNewStart\new_start.dist\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
Source: "F:\code.fy.com\myNewStart\new_start.dist\*"; 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

nuitka脚本如下:

# coding:utf-8
import json
import shutil
import time
import zipfile, os
import hashlib



# 创建多级文件(不含文件)
def create_dir(file_path):
    if os.path.exists(file_path) is False:
        try:
            os.makedirs(file_path)
        except Exception as e:
            pass
#先移除 上次打包得缓存

old_cache_path = os.path.join(os.getcwd(),'new_start.dist')
if os.path.exists(old_cache_path):
    try:
        shutil.rmtree(old_cache_path)
    except Exception as e:
        print(str(e))
start_time = time.time()
version = '1.0.67'
with open('config.json',encoding='utf-8')as f:
    res =  f.read()
config = json.loads(res)
config['appInfo']['version']=version
with open('config.json','w',encoding='utf-8')as f:
    f.write(json.dumps(config,indent=1,ensure_ascii=False))

strr = r'nuitka --windows-icon-from-ico="./logo.ico"  --standalone  --mingw64 --enable-plugin=pyqt5 --nofollow-import-to=psutil,flask,requests,email,http,sqlalchemy,cryptography,pymysql,pycparser,urllib3,idna,sqlite3,Crypto  --show-progress --show-modules   --include-data-dir=cate=cate --include-data-files=config.json=config.json --include-data-files=upexe.exe=upexe.exe  --windows-disable-console --windows-uac-admin  --remove-output ./new_start.py'
# # #debug
# strr = r'nuitka --windows-icon-from-ico="./logo.ico"  --standalone  --mingw64 --enable-plugin=pyqt5   --nofollow-import-to=psutil,flask,requests,email,http,sqlalchemy,cryptography,pymysql,pycparser,urllib3,idna,sqlite3,Crypto  --show-progress --show-modules   --include-data-dir=cate=cate  --include-data-files=./libs/libEGL.dll=libEGL.dll --include-data-files=./libs/libGLESv2.dll=libGLESv2.dll  --include-data-files=./libs/d3dcompiler_47.dll=d3dcompiler_47.dll --include-data-files=config.json=config.json --include-data-files=upexe.exe=upexe.exe --windows-uac-admin  --remove-output ./new_start.py'
# # #打包命令
os.system(strr)
package_path = 'need_pkg\*'
libs_path = 'libs\*'
gen_dir_path = 'new_start.dist\*'
#复制包文件 进入dist里面
os.system('xcopy /y /s "{0}" "{1}"'.format(package_path,gen_dir_path))
os.system('xcopy /y /s "{0}" "{1}"'.format(libs_path,gen_dir_path))
# # 复制包文件进入 打包文件内
path = os.path.join('F:\软件打包\你的软件名打包记录', 'package',version+"__"+time.strftime("%Y-%m-%d_%H-%M-%S", time.localtime()))
if not os.path.exists(path):
    create_dir(path)
zip_path = os.path.join(path, 'test.zip')
if os.path.exists(zip_path):
    os.remove(zip_path)
# # 执行方法
zip_strr = 'WinRAR -ep1  a -r -x*upexe.exe {0} "{1}"'.format(zip_path, gen_dir_path)
os.system(zip_strr)
with open(os.path.join(path, 'test.zip'), 'rb') as f:
    res = f.read()
with open(os.path.join(path, 'info.txt'),'w',encoding='utf-8')as f:
    f.write('md5:'+hashlib.md5(res).hexdigest()+'\n')
    f.write('version:'+version+'\n')
exe_strr = 'ISCC.exe ./yududouo3.iss'
os.system(exe_strr)
# shutil.move(os.path.join('C:\Users\NING\\ MEI\Desktop\output','新版本鱼多多安装包.exe'),path)
if os.name == 'nt':
    home = os.getenv('USERPROFILE')
else:
    home = os.getenv('HOME')

shutil.move(os.path.join('output','新版本你的软件名安装包.exe'), path)
end_time = time.time()
print(end_time-start_time)

总结

程序爱好者经常要把自己编写的软件进行打包成可安装的exe,以上保姆级教程让大家傻瓜式学会打包。喜欢私聊。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

逆向导师

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值