“无法执行脚本”由innosetup创建的可执行文件中的错误

问题描述 投票:0回答:1

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

这只是在与可执行文件相同的位置创建一个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时,出现以下错误。

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
python exe inno-setup distribution software-distribution
1个回答
0
投票

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

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

__文件__是当前文件的名称,如果您在模块内部或使用execfile()启动脚本,则它可能与main 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')

© www.soinside.com 2019 - 2024. All rights reserved.