I cannot compile two .py
files into stand alone executable that does not need to be installed using py2exe . I followed the instructions on this post post and wrote my setup file as follows:
from distutils.core import setup
import py2exe
import sys, os
setup(
options = {'py2exe': {'bundle_files': 1, 'compressed': True}},
windows=[{'script': "main.py"}],
zipfile = None,
)
My problem however, is that I have two .py files
, my main file main.py
, and my background_image.py
file (which contains base 64 image strings). As a result, py2exe compiles these two file separately as you can see here in this image:
As a result, I receive the following error when I try to run the main compiled file.
Traceback (most recent call last):
File 'main.py", line 8, in <module>
ImportError: No Module named 'background_image'
This is a reduced version of my program from main.py
; the program draws a canvas with a background.
import tkinter as tk
from PIL import ImageTk, Image
import background_images
#image variables
background = images.background_image
close_icon = images.close_icon
#root window creation
root=tk.Tk()
root.geometry(600, 600)
#canvas widget
photo = tk.PhotoImage(data=background)
width, height = photo.width(), photo.height()
canvas = tk.Canvas(root, width=width, height=height, bd=-2)
canvas.pack()
canvas.create_image(0, 0, image=photo, anchor="nw")
root.mainloop()
and here is shortened background_image from background_images.py
background_image = """
iVBORw0KGgoAAAANSUhEUgAA #... continues on
"""