when I try to create a onefile executable with pyinstaller all the button-icons are removed. I want to use relative paths so that the .exe also runs on other computers. I found some old postings but I did not get these to work.
Python-Code:
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(QtWidgets.QMainWindow):
def __init__(self, debugging=False):
super().__init__()
self.__setupUi()
self.__retranslateUi()
QtCore.QMetaObject.connectSlotsByName(self)
self.show()
def __setupUi(self):
self.setObjectName('MainWindow')
self.resize(400, 100)
self.centralwidget=QtWidgets.QWidget(self)
self.centralwidget.setObjectName('centralwidget')
self.verticalLayout=QtWidgets.QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName('verticalLayout')
self.pushButton=QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setText('')
icon=QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap('Icons/test.png'), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.pushButton.setIcon(icon)
self.pushButton.setIconSize(QtCore.QSize(32, 32))
self.pushButton.setObjectName('pushButton')
self.verticalLayout.addWidget(self.pushButton)
self.setCentralWidget(self.centralwidget)
def __retranslateUi(self):
_translate=QtCore.QCoreApplication.translate
self.setWindowTitle(_translate('MainWindow', 'MainWindow'))
if __name__=='__main__':
app=QtWidgets.QApplication(sys.argv)
uiObj=Ui_MainWindow()
sys.exit(app.exec())
PyInstaller-Command:
python -m PyInstaller --onefile --windowed --add-data Icons/*.png;Icons test.py
And the .spec content:
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(['test.py'],
pathex=['C:\\Users\\User\\Desktop\\Neuer Ordner'],
binaries=[],
datas=[('Icons/*.png', 'Icons')],
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='test',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=False )
So how to fix this? Thx.