在Matklot错误中嵌入matplotlib

时间:2014-08-13 13:02:26

标签: python macros matplotlib tkinter

几天之后,我回到了我的电脑,注意到我的图形脚本不再有效,尽管图形代码或计算机库没有任何变化。我决定进行调查,来自here的示例脚本不再有效并抛出此错误

objc[34475]: Class TKApplication is implemented in both /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and /Library/Frameworks/Tk.framework/Versions/8.6/Tk. One of the two will be used. Which one is undefined.
objc[34475]: Class TKMenu is implemented in both /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and /Library/Frameworks/Tk.framework/Versions/8.6/Tk. One of the two will be used. Which one is undefined.
objc[34475]: Class TKContentView is implemented in both /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and /Library/Frameworks/Tk.framework/Versions/8.6/Tk. One of the two will be used. Which one is undefined.
objc[34475]: Class TKWindow is implemented in both /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and /Library/Frameworks/Tk.framework/Versions/8.6/Tk. One of the two will be used. Which one is undefined.

在下面提到的导入和下面的致命错误uport运行Tk.Tk()

Traceback (most recent call last):
  File "/Users/username/Desktop/Projects/name/test.py", line 20, in <module>
    root = Tk.Tk()
  File "/usr/local/Cellar/python3/3.3.3/Frameworks/Python.framework/Versions/3.3/lib/python3.3/tkinter/__init__.py", line 1789, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError

我很困惑,如果我在虚拟环境中工作的话,为什么它指向我的Brewed(我在Os X上,如果这有帮助)python。值得注意的是,Tkinter和Matplotlib分开工作,这只是一行

from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg

打破了东西。

EDIT1:我累了重新安装Tcl,python和virtualenv。没有解决问题:(

EDIT2:在python2(innsted of 3)解释器中运行相同的东西。错误更详细。

/Library/Frameworks/Tk.framework/Resources/Scripts/tk.tcl: version conflict for package "Tcl": have 8.5.9, need 8.6
version conflict for package "Tcl": have 8.5.9, need 8.6
    while executing
"package require Tcl 8.6"
    (file "/Library/Frameworks/Tk.framework/Resources/Scripts/tk.tcl" line 14)
    invoked from within
"source /Library/Frameworks/Tk.framework/Resources/Scripts/tk.tcl"
    ("uplevel" body line 1)
    invoked from within
"uplevel #0 [list source $file]"


This probably means that tk wasn't installed properly.

好的问题是Tcl的问题。我没有触及它,它曾经工作过。

EDIT3:尝试重新安装ActiveTcl - 没有改变任何内容

EDIT4:在/System/Library/Frameworks/Tk.framework/Versions/下我安装了Tk版本8,5和8.4

/Library/Frameworks/Tk.framework/Versions/下的

我安装了8.6版。

我尝试禁用版本8.6以反映脚本处理的其他计算机上的配置。得到了这个错误:

ImportError: dlopen(/Users/mik/Desktop/Projects/ODE/virtenv/lib/python3.4/site-packages/matplotlib/backends/_tkagg.so, 2): Library not loaded: /Library/Frameworks/Tcl.framework/Versions/8.6/Tcl
  Referenced from: /Users/mik/Desktop/Projects/ODE/virtenv/lib/python3.4/site-packages/matplotlib/backends/_tkagg.so
  Reason: image not found

两台计算机使用相同的Python版本(3.4.1)和相同的matplotlib版本(1.3.1)。有没有办法指定matklotlib使用哪个Tk / Tcl版本?

编辑6:我使用Time Machine验证了自上次脚本运行以来没有任何Tk / Tcl veriosn文件发生变化。

编辑7:有点解决方案:

将matplotlib文件夹从工作计算机的site-packages复制到显示这些错误的文件夹修复了该问题。我很高兴知道将来如何设置matplotlib使用的tcl版本。

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。 Matplotlib在安装时会查找Tcl / Tk框架。我暂时禁用了2.6版本,重新安装了matplotlib并重新启用了2.6版本。作品