"Failed to execute script" innosetup 创建的可执行文件出错
"Failed to execute script" error in executable file created by innosetup
我创建了一个如下所示的简单脚本。
这只是在与可执行文件相同的位置创建一个 text.txt 文件。
test.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 时,出现以下错误。
好像是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
__ 文件 __ 是 当前文件 的名称,如果您在模块中或者如果您使用执行文件()
Difference between --file-- and sys.argv[0]
test.exe 对比 test.py
os.path.abspath(sys.argv[0]) 可能会失败 如果不是 test.py 与 test.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')
我创建了一个如下所示的简单脚本。
这只是在与可执行文件相同的位置创建一个 text.txt 文件。
test.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 时,出现以下错误。
好像是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
__ 文件 __ 是 当前文件 的名称,如果您在模块中或者如果您使用执行文件()
Difference between --file-- and sys.argv[0]
test.exe 对比 test.py
os.path.abspath(sys.argv[0]) 可能会失败 如果不是 test.py 与 test.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')