I tried to change it to an exe file with Pyinstaller, but an error message came up and it didn't work

Asked 2 years ago, Updated 2 years ago, 156 views

Each time a button with a sheet name is pressed by loading an Excel file with multiple sheets, one of each sheet's data is randomly displayed in the Text window, copied to the clipboard, and the sheet currently loaded into the State is displayed. Whenever I press Ctrl+A, I made a program that allows me to attach the contents of the clipboard, randomly selects other data, and copies it to the clipboard. It worked well with the py file, but RecursionError: maximum recursion depth exceeded occurred when trying to create the exe file with pyinstaller. When I made it with auto-py-to-exe, the file was created, but the failed to execute script error was displayed and it did not run. I don't think there's a recursive function, but I don't know why.

from tkinter import *
import openpyxl
import random
import pyperclip
import keyboard
from time import sleep

wb = openpyxl.load_workbook("sample.xlsx")
sh1 = wb.active
sh1 = wb["A"]
sh2 = wb.active
sh2 = wb["B"]
sh3 = wb.active
sh3 = wb["B"]
sh4 = wb.active
sh4 = wb["D"]
sh5 = wb.active
sh5 = wb["E"]

root = Tk()
root.title ("Excel Random Inputer")
root.geometry("400x350")
root.resizable(False, False)


def p1():
    text.delete(1.0, END)
    state.delete(1.0, END)
    ran1 = sh1.cell(row = random.randrange(1, len(sh1["A"]) + 1), column = 1).value
    text.insert(1.0, ran1)
    pyperclip.copy(ran1)
    state.insert(1.0, "A")

def p2():
    text.delete(1.0, END)
    state.delete(1.0, END)
    ran1 = sh2.cell(row = random.randrange(1, len(sh2["A"]) + 1), column = 1).value
    text.insert(1.0, ran1)
    pyperclip.copy(ran1)
    state.insert(1.0, "B")

def p3():
    text.delete(1.0, END)
    state.delete(1.0, END)
    ran1 = sh3.cell(row = random.randrange(1, len(sh3["A"]) + 1), column = 1).value
    text.insert(1.0, ran1)
    pyperclip.copy(ran1)
    state.insert(1.0, "C")

def p4():
    text.delete(1.0, END)
    state.delete(1.0, END)
    ran1 = sh4.cell(row = random.randrange(1, len(sh4["A"]) + 1), column = 1).value
    text.insert(1.0, ran1)
    pyperclip.copy(ran1)
    state.insert(1.0, "D")

def p5():
    text.delete(1.0, END)
    state.delete(1.0, END)
    ran1 = sh5.cell(row = random.randrange(1, len(sh5["A"]) + 1), column = 1).value
    text.insert(1.0, ran1)
    pyperclip.copy(ran1)
    state.insert(1.0, "E")

def p6():
    text.delete(1.0, END)
    state.delete(1.0, END)
    pyperclip.copy("")
    state.insert(1.0, "")

def kt(Event):
    s = state.get(1.0, END)
    if s.strip() in "A":
        keyboard.send("ctrl+v")
        sleep(0.1)
        text.delete(1.0, END)
        ran1 = sh1.cell(row = random.randrange(1, len(sh1["A"]) + 1), column = 1).value
        text.insert(1.0, ran1)
        pyperclip.copy(ran1)
    elif s.strip() in "B":
        keyboard.send("ctrl+v")
        sleep(0.1)
        text.delete(1.0, END)
        ran1 = sh2.cell(row = random.randrange(1, len(sh2["A"]) + 1), column = 1).value
        text.insert(1.0, ran1)
        pyperclip.copy(ran1)
    elif s.strip() in "C":
        keyboard.send("ctrl+v")
        sleep(0.1)
        text.delete(1.0, END)
        ran1 = sh3.cell(row = random.randrange(1, len(sh3["A"]) + 1), column = 1).value
        text.insert(1.0, ran1)
        pyperclip.copy(ran1)
    elif s.strip() in "D":
        keyboard.send("ctrl+v")
        sleep(0.1)
        text.delete(1.0, END)
        ran1 = sh4.cell(row = random.randrange(1, len(sh4["A"]) + 1), column = 1).value
        text.insert(1.0, ran1)
        pyperclip.copy(ran1)
    elif s.strip() in "E":
        keyboard.send("ctrl+v")
        sleep(0.1)
        text.delete(1.0, END)
        ran1 = sh5.cell(row = random.randrange(1, len(sh5["A"]) + 1), column = 1).value
        text.insert(1.0, ran1)
        pyperclip.copy(ran1)

b1 = Button(root, text="A", command=p1)
b2 = Button(root, text="B", command=p2)
b3 = Button(root, text="C", command=p3)
b4 = Button(root, text="D", command=p4)
b5 = Button(root, text="E", command=p5)
b6 = Button(root, text="Clear", command=p6)
text = Text(root)
state = Text(root)

b1.place(x=10, y=10, width=70, height=30)
b2.place(x=10, y=50, width=70, height=30)
b3.place(x=10, y=90, width=70, height=30)
b4.place(x=10, y=130, width=70, height=30)
b5.place(x=10, y=170, width=70, height=30)
b6.place(x=10, y=210, width=70, height=30)
text.place(x=120, y=10, width=260, height=320)
state.place(x=10, y=300, width=70, height=30)

keyboard.add_hotkey("ctrl+a", kt, args=[""])

wb.close()
root.mainloop()

failed-to-execute-script pyinstaller maximun-recursion-depth-exceeded

2022-09-21 18:05

2 Answers

I roughly looked it up and found that there were people who were making executable files with PyInstaller and encountered this error about two years ago. You're not lucky.

https://github.com/pyinstaller/pyinstaller/issues/2919

There are some tips to change the Python version, so try them one by one.


2022-09-21 18:05

I am an error because of openpyxl.

Download pyinstaller to the latest developer version and try it.

If you get the same error, open it with a notepad and

at the top

import sys

sys.setrecursionlimit(5000)

After you put in the , try the pyinstaller with the spec file.

It works well.


2022-09-21 18:05

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.