Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
cx-Freeze exe doesn't work
#1
Hi, I created .exe file from my .py file with cx_Freeze. Exe file created successfully, but now, when I want to run file, only command window opens in a moment and closes. So how can I solve this problem?

This is my app.py.
import os
import subprocess
from tkinter import *
from tkinter import messagebox


class Dict(object):

    def __init__(self, idx: int, name: str, pdf: str, txt: str, n: int):
        self.id = int(idx)
        self.name = name
        self.pdf = pdf
        self.txt = txt
        self.n = int(n)

    def __repr__(self):
        return f'Dict: {self.id}; {self.name}; {self.pdf}; {self.txt}; {self.n}'


class Application(object):

    def __init__(self):
        # default pdf reader's path
        self.reader = self.adobe_reader_exe()
        self.dicts = []
        self.page = 1

        super().__init__()

    def adobe_reader_exe(self, path: str='Program Files (x86)') -> str:
        # name of 32 bit Adobe Reader executable
        acro_exe = 'AcroRd32.exe'

        # scan program files folder
        for root, dirs, files in os.walk(os.path.join('c:\\', path)):
            if acro_exe in files:
                return os.path.join(root, acro_exe)

        # try to search in 64 bit executable
        return None

    def adobe_open_pdf(self, filepath: str, page: int=1):
        subprocess.Popen([self.reader, '/A', f'page={page}', filepath])

    def import_dicts(self):
        with open("Dict_list.txt", "r", encoding="utf-8-sig") as fd:
            for record in fd:
                self.dicts.append(Dict(*record.split('; ')))

    def find_page(self, dt, word: str) -> int:
        with open(dt.txt, encoding="utf-8-sig" ) as file:
            dic = [line.rstrip( '\n' ) for line in file]
        word = word.get()
        word = word.title()
        i = 0
        while i < (len( dic ) - 1):
            if word >= dic[i] and word < dic[i + 1]:
                self.page = i + dt.n
                return self.page
            i += 1
        return False

    def run(self):
        self.import_dicts()

        root = Tk()
        root.title( "ԵԳԻ" )
        root.configure( background="#83d0c9" )
        root.iconbitmap( 'logo.ico' )

        text = Label( root, bg="#83d0c9", text="Մուտքագրեք բառը: " ).grid(
            row=1, pady=5 )

        word = Entry( root )
        word.grid( row=2, pady=5 )
        word.focus_set()

        text = Label( root, bg="#83d0c9",
                      text="Ընտրեք բառարանը, որում ցանկանում եք փնտրել բառը․" )\
                     .grid(row=3, pady=5 )

        for dct in self.dicts:
            row = 3 + dct.id
            btn = Button(root, wraplength=700, width=100, text=dct.name,
                         anchor=W, bg="#009688", command=lambda a=dct:
                        self.adobe_open_pdf(a.pdf, self.find_page(a, word)))
            btn.grid(row=row, pady=3, padx=5)
        root.geometry("750x500")
        root.mainloop()


if __name__ == '__main__':
    try:
        app = Application()
        app.run()
    except KeyboardInterrupt:
        print('Exiting application...')
and this is my setup.py

from cx_Freeze import setup, Executable

setup(name='IGS_Library', version='0.1', executables=[Executable("app.py")])
Reply
#2
Check for log file with the error in the same folder where the exe is
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Why doesn't calling a parent constructor work with arbitrary keyword arguments? PurposefulCoder 4 941 Jun-24-2023, 02:14 PM
Last Post: deanhystad
  Why doesn't this code work? What is wrong with path? Melcu54 7 1,793 Jan-29-2023, 06:24 PM
Last Post: Melcu54
  color code doesn't work harryvl 1 892 Dec-29-2022, 08:59 PM
Last Post: deanhystad
  Tkinter + Multiprocessing startmap makes UI Freeze sunny9495 4 1,396 Nov-13-2022, 12:49 PM
Last Post: sunny9495
  client.get_all_tickers() Doesn't work gerald 2 1,717 Jun-16-2022, 07:59 AM
Last Post: gerald
  pip doesn't work after Python upgrade Pavel_47 10 4,209 May-30-2022, 03:31 PM
Last Post: bowlofred
  For Loop Works Fine But Append For Pandas Doesn't Work knight2000 2 2,020 Dec-18-2021, 02:38 AM
Last Post: knight2000
  Class Method to Calculate Age Doesn't Work gdbengo 1 1,712 Oct-30-2021, 11:20 PM
Last Post: Yoriz
  Process doesn't work but Thread work ! mr_byte31 4 2,627 Oct-18-2021, 06:29 PM
Last Post: mr_byte31
  Psycopg2 doesn't work with python2 MedianykEugene 3 2,962 Aug-10-2021, 07:00 AM
Last Post: ndc85430

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020