Tkinter pyinstaller包GUI应用程序

Tkinter pyinstaller包GUI应用程序,tkinter,exe,pyinstaller,Tkinter,Exe,Pyinstaller,我正在尝试将我的应用程序打包,作为独立应用程序发送给用户 我已尝试通过键入以下内容来使用pyinstaller: pyinstaller--onefile TimeDomainAnalysis.py 这将完成并提供一个可执行文件,但它不会打开并返回附加的错误消息 我的部分GUI代码(参考图片的位)如下所示: from Tkinter import * from PIL import Image, ImageTk import tkMessageBox from tkFileDialog impo

我正在尝试将我的应用程序打包,作为独立应用程序发送给用户

我已尝试通过键入以下内容来使用pyinstaller: pyinstaller--onefile TimeDomainAnalysis.py

这将完成并提供一个可执行文件,但它不会打开并返回附加的错误消息

我的部分GUI代码(参考图片的位)如下所示:

from Tkinter import *
from PIL import Image, ImageTk
import tkMessageBox
from tkFileDialog import askopenfilename
import numpy as np
import matplotlib 
matplotlib.use('TkAgg')
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg,         NavigationToolbar2TkAgg
from numpy import arange, sin, pi

# Each class is a frame in the root main window
class HomeFrame(object):
"""docstring for HomeFrame"""
def __init__(self, root):   # constructor places the widgets in the home     frame.  Each instance (self) is a new window placed in the main window
    super(HomeFrame, self).__init__()
    self.root=root      #oull the root window from the input constructor
    self.root.attributes("-topmost", False)
    self.root.title("Wave Analyzer App")
    self.Frame1=Frame(self.root)    #Create the home frame
    self.Frame1.pack()  #pack the frame.  It must be on a new line to be a     referencable object
    lab=Label(self.Frame1,text='Time Domain Wave Analyzer', font=("Helvetica", 30)).pack()  #label object within the frame that is not dynamic or to be passed to other instances

    self.But1=Button(self.Frame1,text='Get Started',command=self.B1Click)   #place a button in the frame
    self.But1.pack()

    path = "waves-circles-285359_960_720.jpg"

    #Creates a Tkinter-compatible photo image, which can be used everywhere Tkinter expects an image object.
    img = ImageTk.PhotoImage(Image.open(path))

    # load = Image.open("waves-circles-285359_960_720.jpg")
    # render = ImageTk.PhotoImage(load)
    IMLab=Label(self.Frame1,text='here i am',image=img)
    IMLab.image = img # You must keep a ref to the image else it gets destroyed!!
    IMLab.pack(side = "bottom", fill = "both", expand = "yes")
    lab2=Label(self.Frame1,text='By Ben Howey', font=("Helvetica", 12))     #label object within the frame that is not dynamic or to be passed to other instances
    lab2.pack(side=RIGHT)
已解决:

添加

    def resource_path(self,relative_path):
        if hasattr(sys, '_MEIPASS'):
            return os.path.join(sys._MEIPASS, relative_path)
        return os.path.join(os.path.abspath("."), relative_path)
在从exe运行时返回MEIPASS目录中的绝对文件路径,或在Python中运行时返回绝对文件路径。然后通过编辑.spec文件将文件添加到包中以添加图像文件。

解决:

添加

    def resource_path(self,relative_path):
        if hasattr(sys, '_MEIPASS'):
            return os.path.join(sys._MEIPASS, relative_path)
        return os.path.join(os.path.abspath("."), relative_path)

在从exe运行时返回MEIPASS目录中的绝对文件路径,或在Python中运行时返回绝对文件路径。然后通过编辑.spec文件将文件添加到包中以添加图像文件。

在解释时是否会产生任何错误?映像是否与可执行文件位于同一目录中?请检查是否有任何隐藏的导入。在Python脚本文件中,可以搜索导入。示例:模块=\导入\导入(名称)。如果是这种情况,请尝试以下链接:并查看“隐藏导入列表”下的内容。此外,如果使用--onefile标志,则可以在临时文件夹中创建该图像。您是否在中修改了pyinstaller.spec文件?当我注释掉对图像的所有引用时,我已经成功地运行了程序。只有当我尝试将此包含在内时,它似乎才失败。我是通过在同一目录下运行pyinstaller--onefile TimeDomainApp.py并使用python脚本和图像来实现这一点的?映像是否与可执行文件位于同一目录中?请检查是否有任何隐藏的导入。在Python脚本文件中,可以搜索导入。示例:模块=\导入\导入(名称)。如果是这种情况,请尝试以下链接:并查看“隐藏导入列表”下的内容。此外,如果使用--onefile标志,则可以在临时文件夹中创建该图像。您是否在中修改了pyinstaller.spec文件?当我注释掉对图像的所有引用时,我已经成功地运行了程序。只有当我尝试将此包含在内时,它似乎才失败。我通过在同一目录下运行pyinstaller--onefile TimeDomainApp.py和python脚本以及图像来实现这一点。