Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib can't work in OS X with error ' TKApplication is implemented in both'

I am using the mac OS X Yosemite 10.10.1, I have installed matplotlib using pip install matplotlib.

I tried a simple application as below.

import matplotlib.pyplot as plt
plt.plot([1,2,3,4], [1,4,9,16], 'ro')
plt.axis([0, 6, 0, 20])
plt.show()

the python application runs and show the window, but without any graph. The command line just gave me a error saying:

Class TKApplication is implemented in both /Users/xisizhe/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.
 Class TKMenu is implemented in both /Users/xisizhe/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.
Class TKContentView is implemented in both /Users/xisizhe/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.
Class TKWindow is implemented in both /Users/xisizhe/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.

How can I choose one of the two ?

like image 581
user824624 Avatar asked Aug 13 '15 20:08

user824624


1 Answers

I had the same problem so my solution was to just not use Tk for the backend after not being able to resolve the issue quickly. Looks like a periodic issue when using Anaconda based on the many threads I found while looking for a solution.

I used this to find available backends

python -c "import matplotlib; print matplotlib.rcsetup.all_backends"

Then added the following to ~/.matplotlib/matplotlibrc to use the Qt4 backend

backend:Qt4Agg
like image 70
Jesse Lopez Avatar answered Oct 26 '22 23:10

Jesse Lopez