【发布时间】:2017-12-11 17:31:08
【问题描述】:
我正在尝试打包我的应用程序以作为独立应用程序发送给人们。
我尝试通过键入以下内容来使用 pyinstaller: pyinstaller --onefile TimeDomainAnalysis.py
这完成并给了我一个可执行文件,但它不会打开并返回附加的错误消息error message on double clicking the .exe
我的部分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)
【问题讨论】:
-
解释时是否产生任何错误?图片和可执行文件在同一个目录吗?
-
检查您是否有任何隐藏的导入。在您的 Python 脚本文件中,您可以搜索 import。示例:模块 = __import__(name)。如果是这种情况,请尝试以下链接:pyinstaller.readthedocs.io/en/stable/when-things-go-wrong.html 并查看列出隐藏的导入。
-
另外,如果您使用 --onefile 标志,则可以在临时文件夹中创建该图像。你是否修改了你的 pyinstaller .spec 文件?
-
当我注释掉对图像的所有引用时,我已经成功地运行了更多的痛苦。仅当我尝试包含此内容时,它似乎才失败。我通过使用 python 脚本和同一目录中的图像运行 pyinstaller --onefile TimeDomainApp.py 来做到这一点。
标签: tkinter exe pyinstaller