3

I tried lots of solving method, none of them worked.

I tried echo $DISPLAY not working

Error Message:

Environment:

Request Method: GET Request URL: http://10.231.xx.xx:8000/upload/

Traceback:

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)

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)

File "/code/fileUpload_app/views.py" in msa_result 174. result1 = generate_hist(db, **processing_dict)

File "/code/fileUpload_app/post_processing.py" in generate_hist 182. fig1 = plt.figure()

File "/opt/conda/lib/python2.7/site-packages/matplotlib/pyplot.py" in figure 527. **kwargs)

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)

File "/opt/conda/lib/python2.7/site-packages/matplotlib/backends/backend_qt4agg.py" in new_figure_manager_given_figure 53. canvas = FigureCanvasQTAgg(figure)

File "/opt/conda/lib/python2.7/site-packages/matplotlib/backends/backend_qt4agg.py" in init 76. FigureCanvasQT.init(self, figure)

File "/opt/conda/lib/python2.7/site-packages/matplotlib/backends/backend_qt4.py" in init 68. _create_qApp()

File "/opt/conda/lib/python2.7/site-packages/matplotlib/backends/backend_qt5.py" in _create_qApp 138. raise RuntimeError('Invalid DISPLAY variable')

Exception Type: RuntimeError at /upload/msa_result/1/ Exception Value: Invalid DISPLAY variable

I am using a docker to host my web project.

My code includes these :

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")
1
  • What do you mean by "echo $DISPLAY" not working? Commented May 3, 2018 at 17:16

2 Answers 2

2

The reason is that I import seaborn before I import matplotlib. This caused matplotlib not running in the right place.

Sign up to request clarification or add additional context in comments.

Comments

2

From here: RuntimeError: Invalid DISPLAY variable

import matplotlib.pyplot as plt
plt.switch_backend('agg')

I used this on a remote machine, with ssh & screen, no X forwarding.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.