title: docker/matplotlib: RuntimeError: Invalid DISPLAY variable
body: <p>I tried lots of solving method, none of them worked.</p>
  
  <p>I tried <code>echo $DISPLAY</code> not working</p>
  
  <p>Error Message:</p>
  
  <blockquote>
    <p>Environment:</p>
    
    <p>Request Method: GET Request URL:
    <a href="http://10.231.xx.xx:8000/upload/" rel="nofollow">http://10.231.xx.xx:8000/upload/</a></p>
    
    <p>Traceback:</p>
    
    <p>File
    "/opt/conda/lib/python2.7/site-packages/django/core/handlers/base.py"
    in get_response
      149.                     response = self.process_exception_by_middleware(e, request)</p>
    
    <p>File
    "/opt/conda/lib/python2.7/site-packages/django/core/handlers/base.py"
    in get_response
      147.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)</p>
    
    <p>File "/code/fileUpload_app/views.py" in msa_result
      174.     result1 = generate_hist(db, **processing_dict)</p>
    
    <p>File "/code/fileUpload_app/post_processing.py" in generate_hist
      182.         fig1 = plt.figure()</p>
    
    <p>File "/opt/conda/lib/python2.7/site-packages/matplotlib/pyplot.py" in
    figure
      527.                                         **kwargs)</p>
    
    <p>File
    "/opt/conda/lib/python2.7/site-packages/matplotlib/backends/backend_qt4agg.py"
    in new_figure_manager
      46.     return new_figure_manager_given_figure(num, thisFig)</p>
    
    <p>File
    "/opt/conda/lib/python2.7/site-packages/matplotlib/backends/backend_qt4agg.py"
    in new_figure_manager_given_figure
      53.     canvas = FigureCanvasQTAgg(figure)</p>
    
    <p>File
    "/opt/conda/lib/python2.7/site-packages/matplotlib/backends/backend_qt4agg.py"
    in <strong>init</strong>
      76.         FigureCanvasQT.<strong>init</strong>(self, figure)</p>
    
    <p>File
    "/opt/conda/lib/python2.7/site-packages/matplotlib/backends/backend_qt4.py"
    in <strong>init</strong>
      68.         _create_qApp()</p>
    
    <p>File
    "/opt/conda/lib/python2.7/site-packages/matplotlib/backends/backend_qt5.py"
    in _create_qApp
      138.                     raise RuntimeError('Invalid DISPLAY variable')</p>
    
    <p>Exception Type: RuntimeError at /upload/msa_result/1/ Exception Value:
    Invalid DISPLAY variable</p>
  </blockquote>
  
  <p>I am using a docker to host my web project.</p>
  
  <p>My code includes these :</p>
  
  <pre><code>import matplotlib as mpl
  mpl.use('Agg')
  import matplotlib.pyplot as plt
  
  def generate_hist(db, **kwargs):
  
  
      fig1 = plt.figure()
  
      hist = mat2[0, 0:pin_num]
  
      fig1 = plt.hist(hist)
  
      plt.savefig("fileUpload_app/static/img/result/hist.jpg")
  </code></pre>