{"id":1062,"hash":"1d8de74a3b18404dfb58adcf320e2913d7456f1fc3ac0f007722b3905475a613","pattern":"_tkinter.TclError: no display name and no $DISPLAY environment variable","full_message":"I am running a simple python script in the server:\n\nimport matplotlib.pyplot as plt\nimport numpy as np\n\nx = np.random.randn(60)\ny = np.random.randn(60)\n\nplt.scatter(x, y, s=20)\n\nout_png = 'path/to/store/out_file.png'\nplt.savefig(out_png, dpi=150)\n\nI try to use the command python example.py in this server which has matplotlib 1.5.1 installed it fails with the error:\n\nTraceback (most recent call last):\n  File \"example.py\", line 7, in <module>\n    plt.scatter(x, y, s=20)\n  File \"/home/USER/.virtualenvs/nnet/lib/python2.7/site-packages/matplotlib/pyplot.py\", line 3241, in scatter\n    ax = gca()\n  File \"/home/USER/.virtualenvs/nnet/lib/python2.7/site-packages/matplotlib/pyplot.py\", line 928, in gca\n    return gcf().gca(**kwargs)\n  File \"/home/USER/.virtualenvs/nnet/lib/python2.7/site-packages/matplotlib/pyplot.py\", line 578, in gcf\n    return figure()\n  File \"/home/USER/.virtualenvs/nnet/lib/python2.7/site-packages/matplotlib/pyplot.py\", line 527, in figure\n**kwargs)\n  File \"/home/USER/.virtualenvs/nnet/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py\", line 84, in new_figure_manager\n    return new_figure_manager_given_figure(num, figure)\n  File \"/home/USER/.virtualenvs/nnet/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py\", line 92, in new_figure_manager_given_figure\n    window = Tk.Tk()\n  File \"/usr/local/lib/python2.7/lib-tk/Tkinter.py\", line 1810, in __init__\n    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)\n_tkinter.TclError: no display name and no $DISPLAY environment variable\n\nWhat is happening here?","ecosystem":"pypi","package_name":"matplotlib","package_version":null,"solution":"Matplotlib chooses  Xwindows backend by default.\nYou need to set matplotlib to not use the Xwindows backend. \n\nAdd this code to the start of your script (before importing pyplot) and try again:\n\nimport matplotlib\nmatplotlib.use('Agg')\n\nOr add to .config/matplotlib/matplotlibrc line backend: Agg to use non-interactive backend.\n\necho \"backend: Agg\" > ~/.config/matplotlib/matplotlibrc\n\nOr when connect to server use ssh -X remoteMachine command to use Xwindows.\n\nAlso you may try to export display: export DISPLAY=mymachine.com:0.0.\n\nFor more info: https://matplotlib.org/faq/howto_faq.html#matplotlib-in-a-web-application-server","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/37604289/tkinter-tclerror-no-display-name-and-no-display-environment-variable","votes":248,"created_at":"2026-04-19T04:52:15.478977+00:00","updated_at":"2026-04-19T04:52:15.478977+00:00"}