py2app构建成功,但应用程序出现“_tkinter.TclError”错误(且没有错误消息!)

13

我正在使用 py2app 0.9 在运行 Python 3.4Mac OSX Yosemite 10.10.1 上,Anaconda发行版,并且使用 Tcl 8.5

在之前的尝试中,构建失败了,但快速搜索后找到了解决这些问题的方法(即在选项中包括'packages':['tkinter','matplotlib']setup.py中,并更改MachOGraph.py的第49行:loader-> loader_path)。

现在,py2app完成了构建,以别名模式运行我的应用程序功能正常,但是当我在正常模式下构建(python setup.py py2app)时,生成的应用程序无法打开,控制台显示以下跟踪:

  

Traceback(最近的调用最后):文件   "/Users/ryankeenan/Desktop/fishing/gui_test/dist/deani.app/Contents/Resources/boot.py",   行355,在_run()文件   "/Users/ryankeenan/Desktop/fishing/gui_test/dist/deani.app/Contents/Resources/boot.py",   行336,在_run() exec(compile(source, path, 'exec'), globals(),   全球())文件   "/Users/ryankeenan/Desktop/fishing/gui_test/dist/deani.app/Contents/Resources/deani.py",   行731,中fishingapp()文件   "/Users/ryankeenan/Desktop/fishing/gui_test/dist/deani.app/Contents/Resources/deani.py",   行536,在init tk.Tk.init(self, *args, **kwargs)文件   "/Users/ryankeenan/Desktop/fishing/gui_test/dist/deani.app/Contents/Resources/lib/python3.4/tkinter/init.py",   第1851行,在init self.tk = _tkinter.create(screenName, baseName,   类名, 交互式, wantobjects, useTk, 同步, 使用)   _tkinter.TclError

令人沮丧的是它没有打印“_tkinter.TclError”的任何错误消息。 我已经搜索了很多并未找到任何解决方案或复制此问题的方法。 我尝试构建各种基于tkinter的应用程序,它们都以相同的方式失败。

这发生在我的代码中第一次调用tk.Tk.init(self,*args,**kwargs)时。

我的setup.py文件如下:

from setuptools import setup 
APP = ['deani.py'] 
DATA_FILES = [] 
OPTIONS = {'packages': ['tkinter','matplotlib'],'argv_emulation': True} 
setup( 
     app=APP, 
     data_files=DATA_FILES, 
     options={'py2app': OPTIONS},     
     setup_requires=['py2app'], )
1个回答

1
我遇到了这个问题,并发现它是由于/Library/Frameworks中tcl/tk的版本冲突导致的。检查构建输出(确保先删除旧构建)以找到对不同版本tcl/tk的引用。我发现我的当前tcl/tk版本是8.6,而py2app正在链接它,但同时py2app也从tcl/tk 8.5复制文件。我通过从`/Library/Frameworks/(Tcl/Tk).framework/Versions`中删除8.5来解决这个问题。
注意:除非您在构建输出中看到了问题并知道没有任何其他(您关心的)版本依赖于该版本,否则不建议删除版本。
然而,这不是我的唯一错误,因为当我删除旧版本时,我发现了一个新的_tkinter.Tcl错误,它指向我的代码中的一个错误。如果您想在不必进入控制台的情况下查看回溯,请尝试在起始代码周围放置try/except语句,将回溯打印到文件中。例如:
        import sys, time, traceback    
        try:
            run()#Your opening code goes here
        except:
            with open('/Path/to/somewhere/tb.txt','a') as file:
                y,mn,d,h,m,s,a,b,c = time.localtime()
                file.write("==================="+str(mn)+'/'+str(d)+' '+
                           str(h)+':'+str(m)+':'+str(s)+
                           "=====================\n")
                traceback.print_exc(file=file)

希望这有所帮助。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接