Home > Back-end >  pyinstaller exe file does not open
pyinstaller exe file does not open

Time:10-22

I made exe file from with pyinstaller. Exe file is 38 MB, it has tkinter but when I click exe file cmd window opens up, CPU works 100%, I waited 10 minutes nothing happened.

How can I resolve it? COde is below;

import sys, subprocess, pkg_resources

required={'tk'}
installed={pkg.key for pkg in pkg_resources.working_set}
missing=required - installed

if missing:
    python=sys.executable
    subprocess.check_call([python,'-m','pip','install', *missing],stdout=subprocess.DEVNULL)

import openpyxl
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import pandas as pd
from openpyxl import load_workbook

import tkinter as tk
from tkinter import ttk

root = tk.Tk()
root.title("Your App crawler")

mainframe = ttk.Frame(root)

mainframe.grid(column=0, row=0, sticky=('N'))
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)

feet = tk.StringVar()
feet_entry = ttk.Entry(mainframe, width=21, textvariable=feet)
feet_entry.grid(column=0, row=1, sticky=(tk.N) ,ipadx=100)
feet_entry.focus()

ttk.Label(mainframe, text="enter SC url ").grid(column=3, row=1, sticky=('N'))

def crawler():

    ttk.Label(mainframe, text="...data retrieving finished. Check file ...").grid(column=0, row=6, sticky='W')
    root.update()

button = ttk.Button(mainframe, text="scrape", command=crawler)
button.grid(column=3, row=7, sticky=tk.S)
root.bind("<Return>", crawler)

for child in mainframe.winfo_children():
    child.grid_configure(padx=5, pady=5)
root.mainloop()

CodePudding user response:

this part of the code is causing the issue, removing it will fix the issue.

import sys, subprocess, pkg_resources

required={'tk'}
installed={pkg.key for pkg in pkg_resources.working_set}
missing=required - installed

if missing:
    python=sys.executable
    subprocess.check_call([python,'-m','pip','install', *missing],stdout=subprocess.DEVNULL)

basically pkg_resources looks for tk, but it doesn't find it ... because it's inside the executable, it cannot be "found" on your disk, so it opens a new process that tries to install it, this calls python with some arguments but your python variable now points to your executable, it will start a new instance of your app ... which will start another version of your app etc.

pyinstaller should package tk if it is imported inside your module, so you don't have to "install" it manually.

  • Related