PyInstaller生成的独立程序可正常运行,经Inno Setup打包安装后却无法加载python310.dll的问题求助
PyInstaller生成的独立程序可正常运行,经Inno Setup打包安装后却无法加载python310.dll的问题求助
大家好,我遇到了一个棘手的问题,想请教下各位:
我在Python 3.10 64位环境下用PyInstaller打包了一个Windows应用,直接运行PyInstaller生成的dist目录里的exe文件完全正常,但用Inno Setup把这个打包好的程序做成安装包后,安装完成启动程序就报错了,错误提示如下:
Failed to load Python DLL
'C:\Program Files\server.manager_internal\python310.dll'
LoadLibrary: The specified module could not be found.
我特意去安装目录检查过,_internal目录确实存在,而且python310.dll也明确在这个目录里,实在搞不懂为什么经过Inno打包安装后就找不到这个文件了...
我的环境信息
- Python版本:3.10.10(64位)
- 操作系统:Windows 10/11 64位
- 打包工具:PyInstaller(使用spec脚本打包)、Inno Setup(向导生成脚本)
我使用的打包配置与命令
1. PyInstaller的spec脚本
import os from pathlib import Path block_cipher = None BASE_DIR = Path(os.getcwd()).resolve() a = Analysis( ['main.py'], pathex=[str(BASE_DIR)], binaries=[], datas=[ (str(BASE_DIR / 'serverfile'), 'serverfile'), ], hiddenimports=[], hookspath=[], hooksconfig={}, runtime_hooks=[], excludes=[], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=block_cipher, noarchive=False, ) pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) exe = EXE( pyz, a.scripts, [], exclude_binaries=True, name='server.manager', debug=False, bootloader_ignore_signals=False, strip=False, upx=True, console=False, ) coll = COLLECT( exe, a.binaries, a.zipfiles, a.datas, strip=False, upx=True, upx_exclude=[], name='server.manager', )
2. Inno Setup的安装脚本
; Script generated by the Inno Setup Script Wizard. ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! ; Non-commercial use only #define MyAppName "server.manager Beta 1.0" #define MyAppVersion "1.0 Beta" #define MyAppPublisher "Minjae Software " #define MyAppExeName "server.manager.exe" #define MyAppAssocName MyAppName + " File" #define MyAppAssocExt ".myp" #define MyAppAssocKey StringChange(MyAppAssocName, " ", "") + MyAppAssocExt [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={{D02C21AB-0CD9-47EB-80B1-190B4C28A9FD} AppName={#MyAppName} AppVersion={#MyAppVersion} ;AppVerName={#MyAppName} {#MyAppVersion} AppPublisher={#MyAppPublisher} DefaultDirName={autopf}\{#MyAppName} UninstallDisplayIcon={app}\{#MyAppExeName} ; "ArchitecturesAllowed=x64compatible" specifies that Setup cannot run ; on anything but x64 and Windows 11 on Arm. ArchitecturesAllowed=x64compatible ; "ArchitecturesInstallIn64BitMode=x64compatible" requests that the ; install be done in "64-bit mode" on x64 or Windows 11 on Arm, ; meaning it should use the native 64-bit Program Files directory and ; the 64-bit view of the registry. ArchitecturesInstallIn64BitMode=x64compatible ChangesAssociations=yes DisableProgramGroupPage=yes ; Uncomment the following line to run in non administrative install mode (install for current user only). ;PrivilegesRequired=lowest OutputDir=C:\Program Files (x86) SolidCompression=yes WizardStyle=modern dark windows11 [Languages] Name: "korean"; MessagesFile: "compiler:Languages\Korean.isl" [Tasks] Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked [Files] Source: "C:\dev\server.manager\dist\server.manager\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion ; NOTE: Don't use "Flags: ignoreversion" on any shared system files [Registry] Root: HKA; Subkey: "Software\Classes\{#MyAppAssocExt}\OpenWithProgids"; ValueType: string; ValueName: "{#MyAppAssocKey}"; ValueData: ""; Flags: uninsdeletevalue Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}"; ValueType: string; ValueName: ""; ValueData: "{#MyAppAssocName}"; Flags: uninsdeletekey Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}\DefaultIcon"; ValueType: string; ValueName: ""; ValueData: "{app}\{#MyAppExeName},0" Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}\shell\open\command"; ValueType: string; ValueName: ""; ValueData: """{app}\{#MyAppExeName}"" ""%1""" [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
我已经尝试过的解决方法
- 手动把
python310.dll复制到安装目录的多个位置(比如和exe同目录),问题依旧 - 清理PyInstaller的缓存后重新打包,再用Inno生成安装包,还是报错
- 右键以管理员身份运行安装后的程序,没有任何改善
我的疑问
为什么直接运行PyInstaller生成的程序完全正常,经过Inno Setup打包安装后就会出现加载python310.dll失败的情况?有没有什么可行的解决办法呢?麻烦各位帮忙看看,谢谢!




