最近服務器系統重裝了一下,原來跑得好好的程序出現了一個“TclError: no display name and no $DISPLAY environment variable”錯誤,百思不得其解,搜了很久,終於找到了解決辦法,記錄如下:
When error occur about this “$DISPLAY not set” when you run Python code that use matplotlib this happened because your matplotlib backend is set to FltkAgg, GTK, GTKAgg, GTKCairo, TkAgg , Wx or WxAgg they required a GUI that why error occur.
To solve this you must specific other backend that not required GUI (Agg, Cairo, PS, PDF or SVG ) when use matplotlib like this
Remember when call savefig(‘filename’) don’t give it extension this will handle by backend that you specific e.g Agg will create file filename.png