-1

Error when try to run the full Login app

this is what I used when

pyinstaller --noconfirm --onefile --windowed 
 "C:/Users/Administrator/Documents/VS CODE DEVELOPMENT/Micheal app/Tkinter Login Page/LoginPage.py"

Also the current login app has no images or data for now, all has be removed to track the error but after removing all images I have the code below. The sample app is runing as desired but after converting to exe, the error message as shown in the image below is seen. how can I resolve this?

from captcha.image import ImageCaptcha
import random

# Define a function to generate a random captcha string
def generate_captcha():
    # Define the character set for the captcha
    char_set = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
    captcha = ''
    # Generate a random 6-character captcha string
    for i in range(6):
        captcha += random.choice(char_set)
    return captcha

# Define a function to create a captcha image and display it in the GUI
def create_captcha_image():
    captcha = generate_captcha()
    image = ImageCaptcha().generate(captcha)
    # Convert the captcha image to a Tkinter PhotoImage
    photo = tk.PhotoImage(data=image.getvalue())
    captcha_label.configure(image=photo)
    captcha_label.image = photo
    return captcha

# Define a function to handle the form submission
def submit_form():
    email = email_entry.get()
    password = password_entry.get()
    user_captcha = captcha_entry.get()
    # Validate the captcha
    if user_captcha == captcha_text:
        print(f"Email: {email}\nPassword: {password}")
        # Add code to create the account here
    else:
        print("Incorrect captcha, please try again.")
        create_captcha_image()

# Create a GUI window
root = tk.Tk()
root.title("Create an Account")

# Create a label and entry for the email address
email_label = tk.Label(root, text="Email Address:")
email_label.pack()
email_entry = tk.Entry(root)
email_entry.pack()

# Create a label and entry for the password
password_label = tk.Label(root, text="Password:")
password_label.pack()
password_entry = tk.Entry(root, show="*")
password_entry.pack()

# Create a label and entry for the captcha
captcha_text = generate_captcha()
captcha_label = tk.Label(root)
captcha_label.pack()
captcha_image = ImageCaptcha().generate(captcha_text)
photo = tk.PhotoImage(data=captcha_image.getvalue())
captcha_label.configure(image=photo)
captcha_label.image = photo
captcha_entry = tk.Entry(root)
captcha_entry.pack()

# Create a button to submit the form
submit_button = tk.Button(root, text="Create Account", command=submit_form)
submit_button.pack()

# Run the GUI window
root.mainloop()

I have remove the images but the error is coming from using captcha for the login app. Recommendation or solutions. Thank you.

Image2: The error message after converting using the sample code

  • Does [this answer](https://stackoverflow.com/a/73167563/8512262) help? When you create a `--onefile` executable with Pyinstaller, it loads assets from the system temp directory, so your app needs to know how to retrieve those assets from temp. – JRiggles Apr 17 '23 at 15:20
  • I used a equivalent of it: 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) – princewill Apr 17 '23 at 16:32
  • or i should change this. Thank you – princewill Apr 17 '23 at 16:33
  • 1
    Post a [mre] and debugging details. – relent95 Apr 18 '23 at 02:13

1 Answers1

0

You need to pass --collect-all captcha when executing pyinstaller.

acw1668
  • 40,144
  • 5
  • 22
  • 34