Pyinstaller exe not working when I change the icon

2019-08-11 07:14发布

问题:

I was making a GUI with python Tkinter. It also uses numpy and matplotlib also. So, I used pyinstaller and make a exe out of the python script. It runs flawlessly and did all what i wanted. Then I tried to change the tk icon from the gui window (i am using windows 10) with this line

master.iconbitmap(default='image.ico')

other than this line i change nothing of the main program. Then using pyinstaller and I made the exe without any error. But when I tried to run the exe it shows "Fatal Error! file.exe returned -1" What am i missing? How to fix this problem?

Also I have an additional problem, the 1st exe i build (without changing the icon) is running on Windows-10 and Windows-8 but not in Windows-7. In windows-7 it shows the same error "Fatal Error! file.exe returned -1"

回答1:

try setting datas like:

a.datas += [('C:\\Users\\KoushikNaskar\\Desktop\\Python\\image.ico', 'image.ico')]

from: http://pythonhosted.org/PyInstaller/spec-files.html#adding-data-files

datas is a list of tuples: (source, dest)



回答2:

Your problem (most likely) is that you are not bundling the icon's image when using pyinstaller to compile your program to a .exe.

You'll see something like this in your .spec file:

a = Analysis(['your_script.py'],
         pathex=['your_path'],
         binaries=None,
         datas=['file_1_path', ....], # Here
         hiddenimports=[],
         hookspath=[],
         runtime_hooks=[],
         excludes=[],
         win_no_prefer_redirects=False,
         win_private_assemblies=False,
         cipher=block_cipher)

Or you could do something like

a.datas += [item1, item2, ...]