This question has been asked before, in here, also here. However, the solution didn't fix the problem for my case.
The original error is, when I try to import matplotlib.pyplot
, I got:
Traceback (most recent call last): File "", line 1, in File "/Users/XX/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.py", line 114, in _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup() File "/Users/XX/anaconda/lib/python2.7/site-packages/matplotlib/backends/init.py", line 32, in pylab_setup globals(),locals(),[backend_name],0) File "/Users/XX/anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.py", line 24, in from matplotlib.backends import _macosx RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends. If you are Working with Matplotlib in a virtual enviroment see 'Working with Matplotlib in Virtual environments' in the Matplotlib FAQ
I followed the solutions to add a ~/.matplotlib/matplotlibrc
file with the code: backend: TkAgg
. After doing that, my error changed to:
/Users/XX/anaconda/lib/python2.7/site-packages/matplotlib/font_manager.py:273: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment. warnings.warn('Matplotlib is building the font cache using fc-list. This may take a moment.') objc[25120]: Class TKApplication is implemented in both /Users/XX/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[25120]: Class TKMenu is implemented in both /Users/XX/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[25120]: Class TKContentView is implemented in both /Users/XX/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[25120]: Class TKWindow is implemented in both /Users/XX/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.
I have no idea how to fix that. I'm not using a virtual machine.
PS: I found out that by adding:
import matplotlib
matplotlib.use('TkAgg')
before import matplotlib.pyplot
, it seems to work. But adding those two lines of code every time is annoying...
What's going on, and how I can fix it?