matplotlib无法在OS X中运行,错误"TKApplication同时实现"

use*_*624 6 python macos matplotlib

我使用的是Mac OS X Yosemite 10.10.1,我已经安装了matplotlib pip install matplotlib.

我尝试了一个简单的应用程序如下.

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

python应用程序运行并显示窗口,但没有任何图形.命令行刚给我一个错误说:

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.
Run Code Online (Sandbox Code Playgroud)

我怎样才能选择其中一个?

小智 3

我遇到了同样的问题,所以我的解决方案是在无法快速解决问题后不使用 Tk 作为后端。根据我在寻找解决方案时发现的许多线程,使用 Anaconda 时似乎是一个周期性问题。

我用它来查找可用的后端

python -c "import matplotlib; print matplotlib.rcsetup.all_backends"
Run Code Online (Sandbox Code Playgroud)

然后添加以下内容~/.matplotlib/matplotlibrc以使用 Qt4 后端

backend:Qt4Agg
Run Code Online (Sandbox Code Playgroud)