Ich erstelle eine EXE-Datei mit pyinstaller, die immer mit einem ausgewählten Icon richtig in den dist-Ordner geschrieben wird (./dist/name.exe).
Man kann sich ein Icon auswählen, das immer korrekt im Distordner mit der EXE angezeigt wird.
In der EXE sind Bild- und Soundverzeichnisse enthalten.
Nun versuche ich, die korrekt erstellte EXE in den Dateiordner zu übertragen, in der auch Bild- und Soundordner sind, damit die Pfade korrekt sind und
die EXE dann auch lauffähig ist.
Dazu versuche ich '--distpath' und '--add-data' zu benutzen und dann die name.spec-Datei nocheinmal mit pyinstaller zu starten.
Mein Code läuft ohne jegliche Ausnahme durch, die EXE-Datei zeigt aber nicht das korrekte Icon an.
Code: Alles auswählen
@staticmethod
def resolve_path(path):
if getattr(sys, "frozen", False):
resolved_path = getattr(sys, '_MEIPASS2', os.path.dirname(os.path.abspath(__file__)))
else:
resolved_path = os.path.abspath(os.path.join(os.getcwd(), path))
return resolved_path
process = subprocess.Popen([spawn.find_executable('pyinstaller.exe'),
SRC_BASE_NAME,
'--clean',
'--onefile',
'--windowed',
'--icon=' + self.resolve_path(TRG_ICN_PATH),
'--name=' + TRG_BASE_NAME,
'--distpath=' + TRG_FOLDER_PATH,
'--add-data=' + self.resolve_path(TRG_ICN_PATH) + ';img'
],
bufsize=1,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
universal_newlines=True)
for line in iter(process.stdout.readline, ""):
self.DISPLAY.insert(tk.END, line, "red")
self.DISPLAY.update_idletasks()
self.DISPLAY.see(tk.END)
output += line
process.wait()
exitCode = process.returncode
if not exitCode == 0:
self.DISPLAY.insert(tk.END, '{0}: {1}'.format(exitCode, output), "red")
self.DISPLAY.update_idletasks()
self.DISPLAY.see(tk.END)
else:
process.terminate()
PyInstaller.__main__.run([os.path.join(TRG_FOLDER_PATH, TRG_BASE_NAME + '.spec')])
Code: Alles auswählen
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(['MAIN.py'],
pathex=['C:\\Users\\chris\\Desktop\\HALLO'],
binaries=[],
datas=[('C:/Users/chris/Desktop/HALLO/icon/spaceship_32.ico', 'img')],
hiddenimports=[],
hookspath=[],
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,
a.binaries,
a.zipfiles,
a.datas,
[],
name='HALLO',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=False , icon='C:\\Users\\chris\\Desktop\\HALLO\\icon\\spaceship_32.ico')