更新2:爲什麼pyplot在osx上給我一個TclError?
我卸載並重新安裝與點,現在發生這種情況。好像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
UPDATE:
我使用暢達蟒蛇。不過,我仍然得到煮出蟒蛇
>>> 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錯誤。我應該永遠不會觸及這些東西。
我卸載蟒蛇包
conda uninstall Tk
conda uninstalal matplotlib
然後我被愚弄TK和重新安裝蟒蛇(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(例如,您可以使用自制軟件和pip,但您可能需要自己安裝C-dependencies),那麼您可以只覈實完整的anaconda目錄。然後確保您使用的是自制軟件的Python,並使用該Python安裝matplotlib(例如,使用該Python附帶的pip)。 – Evert
'rm -rf〜/ anaconda'沒有幫助 – kilojoules
雖然您不能獲得與當前最後一個相同的錯誤信息。 – Evert