title: _tkinter.TclError: no display name and no $DISPLAY environment variable for new OS X Mavericks
body: <p>This is my first post so please be forgiving. </p>
  
  <p>I am trying to create an animation using matplotlib, and I could do this perfectly well until a few days ago, until I upgraded to OS X Mavericks, upon which all hell broke loose. Note, the below code worked in OS X Lion.  </p>
  
  <p>Suddenly I was getting an error message whilst trying to run this code in Mavericks:</p>
  
  <pre><code>import numpy as np
  import matplotlib
  matplotlib.use('TkAgg')
  import matplotlib.pyplot as plt
  import matplotlib.animation as animation
  import pandas as pd
  import mpl_toolkits.mplot3d.axes3d as p3
  
  #-----&gt;READ AND FORMAT DATA-----------------------------------------------#
  .
  .
  .
  .
  
  #-------------------------------------------------------------------------#
  
  # Set up figure &amp; 3D axis for animation
  fig = plt.figure(figsize=(10,10))
  ax = fig.add_axes([0, 0, 1, 1], projection='3d') # Correct way to make 3D plots
  
  # set up lines and points
  lines = sum([ax.plot([], [], [], '-')], [])
  pts = sum([ax.plot([], [], [], 'o')], [])
  
  # Setting the axes properties
  ax.set_xlim3d([-2000, 2000])
  ax.set_xlabel('X')
  ax.set_ylim3d([1350, 1400])
  ax.set_ylabel('Y')
  ax.set_zlim3d([-340, 600])
  ax.set_zlabel('Z')
  
  # set point-of-view: specified by (altitude degrees, azimuth degrees)
  ax.view_init(40, 0)
  ax.set_title('animation')
  ax.grid() # add grid
  
  # Initialisation function: plot the background of each frame
  def init():
      for line, pt in zip(lines, pts):
          # Lines
          line.set_data([], [])
          line.set_3d_properties([])
          # Points
          pt.set_data([], [])
          pt.set_3d_properties([])
      return lines + pts
  
  # Animation function.  This will be called sequentially with the frame number
  def animate(i):
      # we'll step two time-steps per frame.  This leads to nice results.
      i = (2.5 * i)
  
      for line, pt, dat in zip(lines, pts, data):
          x, y, z = dat[:i].T
          # Lines
          line.set_data(x, y)
          line.set_3d_properties(z)
          # Points
          pt.set_data(x[-1:], y[-1:])
          pt.set_3d_properties(z[-1:])
  
      ax.view_init(45, i)
      fig.canvas.draw()
      return lines + pts
  
  #-----&gt;ANIMATION-----------------------------------------------------------#
  
  # Creating the Animation object
  anim = animation.FuncAnimation(fig, animate, init_func=init,
                                 frames=120, interval=30, blit=True)
  # Save as mp4. This requires mplayer or ffmpeg to be installed
  # anim.save('one_marker_3D.mp4', fps=15, extra_args=['-vcodec', 'libx264'])
  
  plt.show()
  </code></pre>
  
  <p>This produces the following error message:</p>
  
  <pre><code>Traceback (most recent call last):
    File "shoulder_animation_walking_straight_3D.py", line 26, in &lt;module&gt;
      fig = plt.figure(figsize=(10,10))
    File "/Users/me/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.py", line 423, in figure
      **kwargs)
    File "/Users/me/anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 79, in new_figure_manager
      return new_figure_manager_given_figure(num, figure)
    File "/Users/me/anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 87, in new_figure_manager_given_figure
      window = Tk.Tk()
    File "/Users/me/anaconda/lib/python2.7/lib-tk/Tkinter.py", line 1745, in __init__
      self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
  _tkinter.TclError: no display name and no $DISPLAY environment variable
  </code></pre>
  
  <p>Now as you can hopefully see, I have attempted to use the TkAgg backend instead of the 'Agg' backend, as recommended by the documentation (<a href="https://wiki.python.org/moin/TkInter" rel="nofollow">https://wiki.python.org/moin/TkInter</a>). This seems to cause problems with the new version of OS X because X11 is not supported anymore, and XQuartz has to be installed instead. This I have done too. But it still give me that same error.  </p>
  
  <p>I also tried installing py33-tkinter using macports, but that didn't work either, but perhaps I did not do it properly. I simply did</p>
  
  <pre><code>sudo port py33-tkinter
  </code></pre>
  
  <p>I am still fairly new to python and unix in general.</p>
  
  <p><strong>UPDATE (22/12/13):</strong></p>
  
  <p>I did the following</p>
  
  <pre><code>Python 2.7.5 |Anaconda 1.8.0 (x86_64)| (default, Oct 24 2013, 07:02:20) 
  [GCC 4.0.1 (Apple Inc. build 5493)] on darwin
  Type "help", "copyright", "credits" or "license" for more information.
  &gt;&gt;&gt;
  &gt;&gt;&gt; import Tkinter
  </code></pre>
  
  <p>Then ran the Tkinter test</p>
  
  <pre><code>&gt;&gt;&gt; Tkinter._test()
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "/Users/me/anaconda/lib/python2.7/lib-tk/Tkinter.py", line 3770, in _test
      root = Tk()
    File "/Users/me/anaconda/lib/python2.7/lib-tk/Tkinter.py", line 1745, in __init__
      self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
  _tkinter.TclError: no display name and no $DISPLAY environment variable
  &gt;&gt;&gt;
  </code></pre>
  
  <p>Might be helpful to someone who knows this better than me.</p>