为什么pyplot在osx上给我一个TclError? [英] Why is pyplot giving me a TclError on osx?
问题描述
更新2:
我通过pip卸载并重新安装,现在发生了这种情况.看来tk没有正确安装.
I uninstalled and reinstalled with pip and now this happens. It seems like tk is not installed right.
$ 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中仍然遇到类似的错误
I was using conda python. However, I still get a simillar error in 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相关的错误.只是消逝的消息.
When I import pyplot I get a Tkinter related error. It's just a waning message.
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.
When I make a plot, I get a weird timestamp and a white window with no plot, and a TclError
. Why is this happening? I am using brew python (installed with the --use-brewed-tk
flag) and 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错误.我绝对不应该碰这些东西.
This looks like it might be a conda error. I should never have touched the stuff.
我卸载了anaconda软件包
I uninstalled the anaconda packages
conda uninstall Tk
conda uninstalal matplotlib
然后我弄错了tk并重新安装了python(基于此github问题)
Then I got dupes tk and reinstalled python (based on this github issue)
brew install homebrew/dupes/tcl-tk
brew uninstall python
brew install python --with-brewed-tk
我现在可以毫无问题地导入pyplot
I can now import pyplot without any problems
In [1]: from matplotlib import pyplot as plt
但是我得到了同样奇怪的错误.如何正确安装tkinter?
But I get the same weird error. How can I properly install 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.
推荐答案
大约10个小时前,我遇到了同样的问题.在按照如何导入matplotlib中的说明后,问题已解决在虚拟环境中
I faced the same problem about 10 hours before. The problem was met after I followed the instruction in How to import matplotlib in virtual env
我发现我已经在anacode和system中安装了tk.但是我不知道Tk中回调的原因.所以我要做的就是更改matplotlib的后端.
I found that I have installed the tk both in anacode and system. But I donot know the reason in callback in Tk. So what I did is change the backend of matplotlib.
cd ~/.matplotlib
vi matplotlibrc
然后更改
backend : TkAgg
到
backend : Qt4Agg
对我有用!
这篇关于为什么pyplot在osx上给我一个TclError?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!