1

I have the same problem with py2exe.

I wrote a script with Tkinter. The iconbitmap of the GUI is a ico image "foologo.ico" located in a specific directory of my computer (C:\Users\fooimage). When I create a executable file with py2exe and i use this executable in an another PC, the software doesn't work because doesn't find the image

I am looking for the best strategy to resolve this problem.

from Tkinter import *

class MainWindow(Frame):
    def __init__(self):
        Frame.__init__(self)
        self.master.title("foo")
        self.master.minsize(350, 150)
        self.master.wm_iconbitmap(default='C:\\Users\\fooimage\\foologo.ico')

if __name__=="__main__":
   d = MainWindow()
   d.mainloop()

i convert this script in a executable file with Pyinstaller-2.01.

python pyinstaller.py --noconsole foo.py

Once i have the executable if i move the foologo.ico file in an other directory (or delete the file) the executable dosen't work. The problem is happen also when i send my executable

Gianni Spear
  • 7,033
  • 22
  • 82
  • 131
  • Possible duplicate of [Bundling data files with PyInstaller (--onefile)](http://stackoverflow.com/questions/7674790/bundling-data-files-with-pyinstaller-onefile) – tfv Oct 25 '16 at 17:15

1 Answers1

0

Here is the complete spec file:

# -*- mode: python -*-
a = Analysis(....)
pyz = PYZ(a.pure)
exe = EXE(pyz,
          a.scripts,
          a.binaries + [('your.ico', 'path_to_your.ico', 'DATA')], 
          a.zipfiles,
          a.datas, 
          name=....
       )

And use it in you app like here:

datafile = "your.ico" 
if not hasattr(sys, "frozen"):   # not packed 
    datafile = os.path.join(os.path.dirname(__file__), datafile) 
else:  
    datafile = os.path.join(sys.prefix, datafile)

root = tk.Tk()
root.iconbitmap(default=datafile)       
Boris
  • 1