[Matplotlib-devel] TclError with TkAgg + matplotlib 1.5.1 + Anaconda/miniconda on OS X 10.11

Joseph Long jlong at stsci.edu
Thu Jul 21 11:31:00 EDT 2016


Hi all,

I'm having issues using TkAgg on matplotlib 1.5.1 from the Anaconda
distribution that I've been unable to get to the bottom of. When trying to
show the plot, I get an exception _tkinter.TclError with the message
"invalid command name "PyAggImagePhoto"" and the plot does not display.
The full gory details are at the end of this message, but in brief to
reproduce (with conda):

$ conda create --yes -n testcase-tkinter-2 python=3.5 matplotlib
$ source activate testcase-tkinter-2
$ python -c "import matplotlib; matplotlib.use('TkAgg'); from matplotlib
import pyplot as plt; plt.plot(1,1); plt.show()"

Displaying the plot gets as far as opening a window, but does not show the
plot. The exception is "_tkinter.TclError: invalid command name
"PyAggImagePhoto""

Based on the warnings emitted (see below), it looks like a library
mismatch of some kind between the system Tk and the Anaconda Tk.

When I reported the issue to the Anaconda maintainers, I was pointed to
this PR: https://github.com/matplotlib/matplotlib/pull/6442 They say that
this will fix the issue, but not until 1.5.2 is released.

My question, I guess, is: will this fix the issue? And will 1.5.2 be
released soon?

Many thanks,

Joseph Long
Space Telescope Science Institute

----

To reproduce the objc warnings on OS X 10.11 with conda:

    $ conda create --yes -n testcase-tkinter-2 python=3.5 matplotlib
    $ source activate testcase-tkinter-2
    $ python -c "import matplotlib; matplotlib.use('TkAgg'); from
matplotlib import pyplot as plt"
    objc[82465]: Class TKApplication is implemented in both
/System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and
/Users/jlong/anaconda/envs/testcase-tkinter-2/lib/libtk8.5.dylib. One of
the two will be used. Which one is undefined.
    objc[82465]: Class TKMenu is implemented in both
/System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and
/Users/jlong/anaconda/envs/testcase-tkinter-2/lib/libtk8.5.dylib. One of
the two will be used. Which one is undefined.
    objc[82465]: Class TKContentView is implemented in both
/System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and
/Users/jlong/anaconda/envs/testcase-tkinter-2/lib/libtk8.5.dylib. One of
the two will be used. Which one is undefined.
    objc[82465]: Class TKWindow is implemented in both
/System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and
/Users/jlong/anaconda/envs/testcase-tkinter-2/lib/libtk8.5.dylib. One of
the two will be used. Which one is undefined.

Python still exits normally in this case.

Using the same environment, you can reproduce the exceptions we've been
seeing whenever plotting with TkAgg. Using Python interactively, we get:

    $ python
    Python 3.5.2 |Continuum Analytics, Inc.| (default, Jul  2 2016,
17:52:12)
    [GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import matplotlib
    >>> matplotlib.use('TkAgg')
    >>> from matplotlib import pyplot as plt
    objc[83006]: Class TKApplication is implemented in both
/System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and
/Users/jlong/anaconda/envs/testcase-tkinter-2/lib/libtk8.5.dylib. One of
the two will be used. Which one is undefined.
    objc[83006]: Class TKMenu is implemented in both
/System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and
/Users/jlong/anaconda/envs/testcase-tkinter-2/lib/libtk8.5.dylib. One of
the two will be used. Which one is undefined.
    objc[83006]: Class TKContentView is implemented in both
/System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and
/Users/jlong/anaconda/envs/testcase-tkinter-2/lib/libtk8.5.dylib. One of
the two will be used. Which one is undefined.
    objc[83006]: Class TKWindow is implemented in both
/System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and
/Users/jlong/anaconda/envs/testcase-tkinter-2/lib/libtk8.5.dylib. One of
the two will be used. Which one is undefined.
    >>> plt.plot([1,2,3], [1,2,3])
    [<matplotlib.lines.Line2D object at 0x111e0f588>]
    >>> plt.show()
    Exception in Tkinter callback
    Traceback (most recent call last):
      File 
"/Users/jlong/anaconda/envs/testcase-tkinter-2/lib/python3.5/site-packages/
matplotlib/backends/tkagg.py", line 22, in blit
        id(data), colormode, id(bbox_array))
    _tkinter.TclError: invalid command name "PyAggImagePhoto"

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File 
"/Users/jlong/anaconda/envs/testcase-tkinter-2/lib/python3.5/tkinter/__init
__.py", line 1550, in __call__
        return self.func(*args)
      File 
"/Users/jlong/anaconda/envs/testcase-tkinter-2/lib/python3.5/site-packages/
matplotlib/backends/backend_tkagg.py", line 283, in resize
        self.show()
      File 
"/Users/jlong/anaconda/envs/testcase-tkinter-2/lib/python3.5/site-packages/
matplotlib/backends/backend_tkagg.py", line 355, in draw
        tkagg.blit(self._tkphoto, self.renderer._renderer, colormode=2)
      File 
"/Users/jlong/anaconda/envs/testcase-tkinter-2/lib/python3.5/site-packages/
matplotlib/backends/tkagg.py", line 30, in blit
        id(data), colormode, id(bbox_array))
    _tkinter.TclError

And that's where it stands.

----

Here are some potentially relevant outputs from otool -L:

    $ otool -L 
/Users/jlong/anaconda/envs/testcase-tkinter-2/lib/python3.5/site-packages/m
atplotlib/backends/_tkagg.so
    
/Users/jlong/anaconda/envs/testcase-tkinter-2/lib/python3.5/site-packages/m
atplotlib/backends/_tkagg.so:
    @rpath/libtk8.5.dylib (compatibility version 8.5.0, current version
8.5.18)
    @rpath/libtcl8.5.dylib (compatibility version 8.5.0, current version
8.5.18)
    /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current
version 52.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current
version 159.1.0)

    $ otool -L 
/Users/jlong/anaconda/envs/testcase-tkinter-2/lib/libtcl8.5.dylib
    /Users/jlong/anaconda/envs/testcase-tkinter-2/lib/libtcl8.5.dylib:
    libtcl8.5.dylib (compatibility version 8.5.0, current version 8.5.18)
    
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundati
on (compatibility version 150.0.0, current version 476.0.0)
    /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current
version 1.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current
version 111.0.0)

    $ otool -L 
/Users/jlong/anaconda/envs/testcase-tkinter-2/lib/libtk8.5.dylib
    /Users/jlong/anaconda/envs/testcase-tkinter-2/lib/libtk8.5.dylib:
    libtk8.5.dylib (compatibility version 8.5.0, current version 8.5.18)
    
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundati
on (compatibility version 150.0.0, current version 476.0.0)
    /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa
(compatibility version 1.0.0, current version 12.0.0)
    /System/Library/Frameworks/Carbon.framework/Versions/A/Carbon
(compatibility version 2.0.0, current version 136.0.0)
    /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit
(compatibility version 1.0.0, current version 275.0.0)
    /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current
version 1.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current
version 111.0.0)
    
/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices
(compatibility version 1.0.0, current version 32.0.0)
    /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version
227.0.0)
    /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit
(compatibility version 45.0.0, current version 949.0.0)
    
/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Applica
tionServices (compatibility version 1.0.0, current version 34.0.0)
    /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation
(compatibility version 300.0.0, current version 677.12.0)

----

Here's the set of all packages installed in the conda environment
testcase-tkinter-2:

    $ conda list
    # packages in environment at
/Users/jlong/anaconda/envs/testcase-tkinter-2:
    #
    cycler                    0.10.0                   py35_0    defaults
    freetype                  2.5.5                         1    defaults
    jwst-visibility (/Users/jlong/software/jwst_visibility) 0.0.1
           <pip>
    libpng                    1.6.22                        0    defaults
    matplotlib                1.5.1               np111py35_0    defaults
    mkl                       11.3.3                        0    defaults
    numpy                     1.11.1                   py35_0    defaults
    openssl                   1.0.2h                        1    defaults
    pip                       8.1.2                    py35_0    defaults
    pyparsing                 2.1.4                    py35_0    defaults
    pyqt                      4.11.4                   py35_4    defaults
    python                    3.5.2                         0    defaults
    python-dateutil           2.5.3                    py35_0    defaults
    pytz                      2016.6.1                 py35_0    defaults
    qt                        4.8.7                         4    defaults
    readline                  6.2                           2    <unknown>
    requests                  2.10.0                    <pip>
    setuptools                23.0.0                   py35_0    defaults
    sip                       4.18                     py35_0    defaults
    six                       1.10.0                   py35_0    defaults
    sqlite                    3.13.0                        0    defaults
    tk                        8.5.18                        0    defaults
    wheel                     0.29.0                   py35_0    defaults
    xz                        5.2.2                         0    defaults
    zlib                      1.2.8                         3    defaults





More information about the Matplotlib-devel mailing list