I was creating a tkinter program which I need to make into exe so I can send it to my friends. so for this program, I needed to add a .png and .ico file. Here is the code I typed in pyinstaller to install the exe
pyinstaller .\u.py -F --noconsole --add-data 'C:\Users\Binoy\Desktop\Techwiz\h.png; .' -i ".\h.ico"
This is my .spec file:
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(['U.py'],
pathex=['C:\\Users\\Binoy\\Desktop\\New folder'],
binaries=[],
datas=[('C:\\Users\\Binoy\\Desktop\\Techwiz\\h.png', '.')],
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='U',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=False , icon='h.ico')
I also got a .txt file regaridng missing modules but in the .txt,they said that these modules won't affect the .exe so I didn't care about it.At first it was running without any problem but then if I delete the .png or if one of my friends download it,it shows the error Failed to execute script U
.
so I tried the resource_path()
function (Pyinstaller and --onefile: How to include an image in the exe file),but didn't work.
So I created a .bat file (Keep error message of exe file which is created by Pyinstaller),and got this error:
Traceback (most recent call last):
File "U.py", line 19, in <module>
File "tkinter\__init__.py", line 4062, in __init__
File "tkinter\__init__.py", line 4007, in __init__
_tkinter.TclError: couldn't open "C:/Users/Binoy/Desktop/Techwiz/h.png": no such file or directory
[8736] Failed to execute script U
Is there any way to store images(.png) with the .exe file as a single .exe file?