Pyinstaller exe not working when I change the icon

送分小仙女□ 提交于 2019-12-11 12:14:53

问题


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, ...]



回答3:


For those still experiencing this issue, I found that pointing the iconbitmap line to the full path will resolve the issue. I was originally having the same problem as the original poster until I entered the full path to my .ico file.

Example:

wm_iconbitmap('E:\icon_name.ico')


来源:https://stackoverflow.com/questions/35974748/pyinstaller-exe-not-working-when-i-change-the-icon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!