Reputation: 975
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")
Upvotes: 3
Views: 2698
Reputation: 1277
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.
Upvotes: 2
Reputation: 975
The reason is that I import seaborn
before I import matplotlib
. This caused matplotlib not running in the right place.
Upvotes: 2