1

UPDATE 2:

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

UPDATE:

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

ORIGINAL POST

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.

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

This looks like it might be a conda error. I should never have touched the stuff.

I uninstalled the anaconda packages

conda uninstall Tk
conda uninstalal matplotlib

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

I can now import pyplot without any problems

In [1]: from matplotlib import pyplot as plt

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.
Thomas Ayoub
  • 29,063
  • 15
  • 95
  • 142
kilojoules
  • 9,768
  • 18
  • 77
  • 149
  • Uninstalling conda's matplotlib seems not to have removed it fully, seen the paths in that last error message. If you're sure you don't want to use conda anymore (e.g., you could use homebrew and pip, but you may need to install C-dependencies yourself), you could just nuke the complete anaconda directory. Then make sure you're using homebrew's Python, and install matplotlib using that Python (e.g., using the pip that came with that Python). –  Dec 21 '15 at 23:06
  • `rm -rf ~/anaconda` did not help – kilojoules Dec 21 '15 at 23:07
  • You can't have gotten the same error message as your current last one though. –  Dec 21 '15 at 23:08
  • You're right. My question isn't current. Now I get a segfault after `plt.show()` – kilojoules Dec 21 '15 at 23:11
  • I uninstalled and reinstalled with pip. I made a second update showing my current problem. – kilojoules Dec 21 '15 at 23:15
  • I'm running Homebrewed Python, and I don't have a `tcl-tk` directory in `/usr/local/opt`. I guess you installed the tcl-tk, then installed Python. Not sure why it picks up both. Unless you really need those tcl-tk libraries, you could try to move them, e.g. `mv /usr/local/opt/tcl-tk /usr/local/opt/tcl-tk-aside`. Then see if Python now still works, just with the system-installed tcl/tk libraries. –  Dec 22 '15 at 00:34

2 Answers2

4

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

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

then change

backend : TkAgg

to

backend : Qt4Agg

And it worked for me !

Community
  • 1
  • 1
Alfred Gao
  • 41
  • 2
0

I had to install PyQt as well. So what I did to fix this issue:

  1. Install PyQt:
    pip install pyqt5
  1. Change the backend of matplotlib by editing ~/.matplotlib/matplotlibrc
    vi ~/.matplotlib/matplotlibrc

change

    backend : TkAgg

to

    backend : Qt5Agg