mattberjon / asc-cnn

Acoustic Scene Auditory (ASC) using Convolutional Neural Network (CNN)
https://asc-cnn.readthedocs.io/en/latest/
GNU General Public License v2.0
3 stars 1 forks source link

tkinter.TclError: no display name and no $DISPLAY environement variable #55

Closed mattberjon closed 6 years ago

mattberjon commented 6 years ago

I ran the script on a distant server that doesn't have any screen connected and ended up with the traceback as follows. The issue is that I don't try to display anything and I didn't specify any debug mode.

Traceback (most recent call last):
  File "/home/mattberjon/asc-cnn/venv/bin/asc", line 11, in <module>
    load_entry_point('asc', 'console_scripts', 'asc')()
  File "/home/mattberjon/asc-cnn/venv/local/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/mattberjon/asc-cnn/venv/local/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/mattberjon/asc-cnn/venv/local/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/mattberjon/asc-cnn/venv/local/lib/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/mattberjon/asc-cnn/venv/local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/mattberjon/asc-cnn/asc/cli.py", line 88, in processing
    display=debug)
  File "/home/mattberjon/asc-cnn/asc/audio.py", line 168, in process_audio
    dynamic_spectrogram(y, filename, block_nb=counter, display=display)
  File "/home/mattberjon/asc-cnn/asc/audio.py", line 61, in dynamic_spectrogram
    librosa.display.specshow(data_freq_db)
  File "/home/mattberjon/asc-cnn/venv/local/lib/python2.7/site-packages/librosa/display.py", line 677, in specshow
    axes = plt.gca()
  File "/home/mattberjon/asc-cnn/venv/local/lib/python2.7/site-packages/matplotlib/pyplot.py", line 950, in gca
    return gcf().gca(**kwargs)
  File "/home/mattberjon/asc-cnn/venv/local/lib/python2.7/site-packages/matplotlib/pyplot.py", line 586, in gcf
    return figure()
  File "/home/mattberjon/asc-cnn/venv/local/lib/python2.7/site-packages/matplotlib/pyplot.py", line 535, in figure
    **kwargs)
  File "/home/mattberjon/asc-cnn/venv/local/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 81, in new_figure_manager
    return new_figure_manager_given_figure(num, figure)
  File "/home/mattberjon/asc-cnn/venv/local/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 89, in new_figure_manager_given_figure
    window = Tk.Tk()
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1823, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable
mattberjon commented 6 years ago

In this case it's an issue related to the chosen backend, in this case Tk that need Xwindow to work properly which you usually don't have available on remote server. The best workaround if plotting the figures are not required is to update the ~/.config/matplotlib/matplotlibrc file and update or add the following line:

backend: Agg
mattberjon commented 6 years ago

This information should probably go in a FAQ for other users who might have the same issue later on.