pyinstaller exe文件未打开



我用pyinstaller制作了exe文件。Exe文件是38MB,它有tkinter,但当我点击Exe文件cmd窗口打开时,CPU工作100%,我等了10分钟什么都没发生。

我该如何解决?COde低于;

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()

这部分代码导致了问题,删除它将解决问题。

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)

基本上pkg_resources查找tk,但它找不到。。。因为它在可执行文件中,所以它不能是";找到";在你的磁盘上,所以它打开了一个新的进程来尝试安装它,这用一些参数调用python,但你的python变量现在指向你的可执行文件,它将启动你的应用程序的一个新实例。。。它将启动你的应用程序等的另一个版本

如果tk被导入到您的模块中,pyinstaller应该打包它,所以您不必";安装";手动操作。

最新更新