【发布时间】:2016-03-28 01:59:12
【问题描述】:
更新 2:
我用 pip 卸载并重新安装,现在发生了这种情况。 tk 好像没有正确安装。
$ ipython
Python 2.7.11 (default, Dec 21 2015, 14:13:54)
Type "copyright", "credits" or "license" for more information.
IPython 4.0.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: from matplotlib import pyplot as plt
objc[66269]: Class TKApplication is implemented in both /usr/local/opt/tcl-tk/lib/libtk8.6.dylib and /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined.
objc[66269]: Class TKMenu is implemented in both /usr/local/opt/tcl-tk/lib/libtk8.6.dylib and /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined.
objc[66269]: Class TKContentView is implemented in both /usr/local/opt/tcl-tk/lib/libtk8.6.dylib and /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined.
objc[66269]: Class TKWindow is implemented in both /usr/local/opt/tcl-tk/lib/libtk8.6.dylib and /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined.
In [2]: plt.plot([1,2,3], [6,5,4])
Out[2]: [<matplotlib.lines.Line2D at 0x110434410>]
In [3]: plt.show()
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 1536, in __call__
return self.func(*args)
File "/usr/local/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 283, in resize
self.show()
File "/usr/local/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 355, in draw
tkagg.blit(self._tkphoto, self.renderer._renderer, colormode=2)
File "/usr/local/lib/python2.7/site-packages/matplotlib/backends/tkagg.py", line 30, in blit
id(data), colormode, id(bbox_array))
TclError
更新:
我使用的是 conda python。但是,我在 brew python 中仍然遇到类似的错误
>>> from matplotlib import pyplot as plt
objc[66099]: Class TKApplication is implemented in both /usr/local/opt/tcl-tk/lib/libtk8.6.dylib and /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined.
objc[66099]: Class TKMenu is implemented in both /usr/local/opt/tcl-tk/lib/libtk8.6.dylib and /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined.
objc[66099]: Class TKContentView is implemented in both /usr/local/opt/tcl-tk/lib/libtk8.6.dylib and /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined.
objc[66099]: Class TKWindow is implemented in both /usr/local/opt/tcl-tk/lib/libtk8.6.dylib and /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined.
>>> plt.plot([1,2,3],[2,3,4])
[<matplotlib.lines.Line2D object at 0x116d81dd0>]
>>> plt.show()
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 1536, in __call__
return self.func(*args)
File "/usr/local/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 278, in resize
self.show()
File "/usr/local/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 350, in draw
tkagg.blit(self._tkphoto, self.renderer._renderer, colormode=2)
File "/usr/local/lib/python2.7/site-packages/matplotlib/backends/tkagg.py", line 24, in blit
tk.call("PyAggImagePhoto", photoimage, id(aggimage), colormode, id(bbox_array))
TclError
原帖
当我导入 pyplot 时,我得到一个与 Tkinter 相关的错误。这只是一个减弱的消息。
In [1]: from matplotlib import pyplot as plt
objc[43731]: Class TKApplication is implemented in both /Users/kilojoules/anaconda/lib/libtk8.5.dylib and /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined.
objc[43731]: Class TKMenu is implemented in both /Users/kilojoules/anaconda/lib/libtk8.5.dylib and /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined.
objc[43731]: Class TKContentView is implemented in both /Users/kilojoules/anaconda/lib/libtk8.5.dylib and /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined.
objc[43731]: Class TKWindow is implemented in both /Users/kilojoules/anaconda/lib/libtk8.5.dylib and /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined.
当我制作一个情节时,我得到一个奇怪的时间戳和一个没有情节的白色窗口,以及一个TclError。为什么会这样?我正在使用 brew python(安装了 --use-brewed-tk 标志)和 pip matplotlib。
In [2]: plt.plot([1,2,3], [2,4,5])
Out[2]: [<matplotlib.lines.Line2D at 0x107f94d50>]
In [3]: 2015-12-21 13:55:02.203 python[43731:912293] setCanCycle: is deprecated. Please use setCollectionBehavior instead
In [3]: plt.show()
2015-12-21 13:55:10.924 python[43731:912293] setCanCycle: is deprecated. Please use setCollectionBehavior instead
Exception in Tkinter callback
Traceback (most recent call last):
File "/Users/kilojoules/anaconda/lib/python2.7/lib-tk/Tkinter.py", line 1536, in __call__
return self.func(*args)
File "/Users/kilojoules/anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 278, in resize
self.show()
File "/Users/kilojoules/anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 350, in draw
tkagg.blit(self._tkphoto, self.renderer._renderer, colormode=2)
File "/Users/kilojoules/anaconda/lib/python2.7/site-packages/matplotlib/backends/tkagg.py", line 24, in blit
tk.call("PyAggImagePhoto", photoimage, id(aggimage), colormode, id(bbox_array))
TclError
这看起来可能是一个 conda 错误。我不应该碰这些东西。
我卸载了 anaconda 包
conda uninstall Tk
conda uninstalal matplotlib
然后我被骗了 tk 并重新安装了 python (based on this github issue)
brew install homebrew/dupes/tcl-tk
brew uninstall python
brew install python --with-brewed-tk
我现在可以毫无问题地导入 pyplot
In [1]: from matplotlib import pyplot as plt
但我得到了同样奇怪的错误。如何正确安装 tkinter?
In [2]: plt.plot([1,2,3], [2,4,5])
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-2-27b4c4180a02> in <module>()
----> 1 plt.plot([1,2,3], [2,4,5])
/Users/kilojoules/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.pyc in plot(*args, **kwargs)
3090 @_autogen_docstring(Axes.plot)
3091 def plot(*args, **kwargs):
-> 3092 ax = gca()
3093 # allow callers to override the hold state by passing hold=True|False
3094 washold = ax.ishold()
/Users/kilojoules/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.pyc in gca(**kwargs)
826 matplotlib.figure.Figure.gca : The figure's gca method.
827 """
--> 828 ax = gcf().gca(**kwargs)
829 return ax
830
/Users/kilojoules/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.pyc in gcf()
460 return figManager.canvas.figure
461 else:
--> 462 return figure()
463
464 fignum_exists = _pylab_helpers.Gcf.has_fignum
/Users/kilojoules/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
433 frameon=frameon,
434 FigureClass=FigureClass,
--> 435 **kwargs)
436
437 if figLabel:
/Users/kilojoules/anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
79 FigureClass = kwargs.pop('FigureClass', Figure)
80 figure = FigureClass(*args, **kwargs)
---> 81 return new_figure_manager_given_figure(num, figure)
82
83
/Users/kilojoules/anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
87 """
88 _focus = windowing.FocusManager()
---> 89 window = Tk.Tk()
90 window.withdraw()
91
/Users/kilojoules/anaconda/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1812 baseName = baseName + ext
1813 interactive = 0
-> 1814 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1815 if useTk:
1816 self._loadtk()
TclError: Can't find a usable tk.tcl in the following directories:
/System/Library/Frameworks/Tcl.framework/Versions/8.5/Resources/Scripts/tk8.5 /System/Library/Frameworks/Tcl.framework/Versions/8.5/Resources/Scripts/tk8.5/Resources/Scripts /System/Library/Frameworks/Tcl.framework/Versions/8.5/Resources/tk8.5 /System/Library/Frameworks/Tcl.framework/Versions/8.5/Resources/tk8.5/Resources/Scripts /Users/kilojoules/anaconda/lib/tk8.5 /Users/kilojoules/anaconda/lib/tk8.5/Resources/Scripts ~/Library/Tcl/tk8.5 ~/Library/Tcl/tk8.5/Resources/Scripts /Library/Tcl/tk8.5 /Library/Tcl/tk8.5/Resources/Scripts /System/Library/Tcl/tk8.5 /System/Library/Tcl/tk8.5/Resources/Scripts /System/Library/Tcl/8.5/tk8.5 /System/Library/Tcl/8.5/tk8.5/Resources/Scripts ~/Library/Frameworks/tk8.5 ~/Library/Frameworks/tk8.5/Resources/Scripts /Library/Frameworks/tk8.5 /Library/Frameworks/tk8.5/Resources/Scripts /System/Library/Frameworks/tk8.5 /System/Library/Frameworks/tk8.5/Resources/Scripts /Users/kilojoules/lib/tk8.5 /Users/kilojoules/anaconda/library
This probably means that tk wasn't installed properly.
【问题讨论】:
-
卸载 conda 的 matplotlib 似乎没有完全删除它,看到最后一条错误消息中的路径。如果您确定不想再使用 conda(例如,您可以使用 homebrew 和 pip,但您可能需要自己安装 C 依赖项),您可以直接删除完整的 anaconda 目录。然后确保您使用的是自制的 Python,并使用该 Python 安装 matplotlib(例如,使用该 Python 附带的 pip)。
-
rm -rf ~/anaconda没有帮助 -
不过,您无法收到与当前上一条相同的错误消息。
-
你是对的。我的问题不是最新的。现在我在
plt.show()之后得到一个段错误 -
我用 pip 卸载并重新安装。我进行了第二次更新,显示了我当前的问题。
标签: macos matplotlib tkinter pip homebrew