You'll need to edit the spec file generated by pyinstaller and add the image to it.
When you use pyinstaller, it outputs a .spec file which is a configuration file. If you wanted to build your program again using the same options, you can just use 'pyinstaller myprogram.spec' instead of 'pyinstaller myprogram.py'
So open up the spec file in a text editor, and put your images in the 'datas' list like this.
datas=[('my_image1.gif', ''),
('my_image2.gif', ''),
('my_image3.gif', ''),
('my_image4.gif', '')],
During the execution of a onefile program created with pyinstaller the data files are unpacked to a temp directory. So to access your img files from within your program use a function like this.
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
(return os.path.join(base_path, relative_path)
I grabbed that function from this link Bundling data files with PyInstaller (--onefile)
Now build your program using your edited spec file. 'pyinstaller myProgram.spec'