gpt4 book ai didi

python - "Failed to execute script"innosetup 创建的可执行文件出错

转载 作者:行者123 更新时间:2023-12-04 10:46:56 25 4
gpt4 key购买 nike

我创建了一个简单的脚本,如下所示。

这只是在与可执行文件相同的位置创建一个 text.txt 文件。

测试.py

import os,sys
test_str = "test"

exeFileDir = os.path.dirname(os.path.abspath(sys.argv[0]))
path_w = os.path.join(exeFileDir, 'test.txt')
with open(path_w, mode='w') as f:
f.write(test_str)

我使用 Pyinstaller 创建了一个 exe 文件。
pyinstaller --noconsole test.py

至此,运行exe文件正确运行代码,并创建了一个test.txt文件。

最后,我使用 innosetup 创建了一个安装文件。

但是,当我在运行 innosetup 后运行 exe 时,出现以下错误。

enter image description here

似乎 innosetup 导致了这样的错误。是什么原因造成的?

我的 innosetup 配置文件如下。
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "testApp"
#define MyAppVersion "1.00"
#define MyAppPublisher "My Company, Inc."
#define MyAppURL "http://www.example.com/"
#define MyAppExeName "test.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={{3D8E37F3-FB32-4AF9-8C64-58C37D542248}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={autopf}\{#MyAppName}
DisableProgramGroupPage=yes
; Uncomment the following line to run in non administrative install mode (install for current user only.)
;PrivilegesRequired=lowest
OutputDir=C:\Users\taichi\Desktop
OutputBaseFilename=mysetup
Compression=lzma
SolidCompression=yes
WizardStyle=modern

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[Files]
Source: "C:\Users\taichi\Desktop\dist\test\test.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Users\taichi\Desktop\dist\test\*"; 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

最佳答案

“好像是 innosetup 造成了这样的错误,是什么原因造成的?”

不,错误来自python脚本! pyinstaller : Failed to execute script

__ 文件 __ 是 的名称当前文件 ,可能与 main script 不同如果您在模块内,或者如果您使用 execfile() 启动脚本

Difference between --file-- and sys.argv[0]

测试.exe 对比 测试.py

os.path.abspath( sys.argv[0] ) 可能会失败如果不是还有测试.py 位于同一文件夹中测试.exe

exeFileDir = os.path.dirname(os.path.abspath(sys.argv[0]))

获取 dirname绝对路径,使用
exeFileDir = os.path.dirname(os.path.abspath(__file__))

现在 path_w应该是正确的
path_w =  os.path.join(exeFileDir, 'test.txt')

关于python - "Failed to execute script"innosetup 创建的可执行文件出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59659931/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com