matplotlib: RuntimeError: Python is not installed as a framework
<p>This question has been asked before, in <a href="https://stackoverflow.com/questions/21784641/installation-issue-with-matplotlib-python">here</a>, also <a href="https://stackoverflow.com/questions/4130355/python-matplotlib-framework-under-macosx">here</a>. However, the solution didn't fix the problem for my case. </p>

<p>The original error is, when I try to <code>import matplotlib.pyplot</code>, I got:</p>

<blockquote>
  <p>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/<strong>init</strong>.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</p>
</blockquote>

<p>I followed the solutions to add a <code>~/.matplotlib/matplotlibrc</code> file with the code: <code>backend: TkAgg</code>. After doing that, my error changed to:</p>

<blockquote>
  <p>/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.</p>
</blockquote>

<p>I have no idea how to fix that. I'm not using a virtual machine. Could you help me? Thank you! </p>

<p>PS: I found out that by adding: </p>

<blockquote>
  <p>import matplotlib<br>
  matplotlib.use('TkAgg')</p>
</blockquote>

<p>before <code>import matplotlib.pyplot</code>, it seems to work. But adding those two lines of codes every time is annoying... Does anyone know what's going on and how I can fix it? Thank you! </p>