I’m trying to set up a simple application, where a user downloads a file in excel format. In order to do that, I’m using tkinter so when the users presses a button, it opens the window to select where to save the file. And that works wonders when running the file locally. The problem begins when I try to host my app in a CentOs server, as I get the following error displayed inside the app:
TclError: no display name and no $DISPLAY environment variable
I’m not sure of this streamlit is the problem here, but my knowledge in this area and on tkinter is quite limited, so any help would be appreciated.
So, here’s a minimum working example to reproduce the error I’m getting:
import streamlit as st
root = tkinter.Tk()
if __name__ == '__main__':
And if i run that code in CentOS this is what i get:
I’ve search online and found this and this but not only am I not using ssh after I update the code access the CentOS server, I’m also not using matplotlib.
Python version: 3.6.8
Streamlit version: 0.58
tkinter version: 8.5
Any help would be appreciated on how to solve this error. And if you have any doubt, please ask.
Hi @marciorpcoelho -
Since your app works locally, but not on a Centos server, I suspect the issue is one of environment. Either the Centos server doesn’t have a windowing environment, or Tkinter expects to be able to open a window in its environment and your browser isn’t in the same Centos environment (as it is when you are doing local development and it works).
One possible way to test this is to remote access your local environment where the app works. Run your code, validate it still works, then use a different computer on your network to access the app. For example, I have a desktop named “threadripper” on my network, and a work laptop. From my work laptop, I can access http://threadripper:8501 to mimic an external server.
I’ll try to test this today on my end and get back to you, but if you get to it first, please let me know if it works.
I was able to try this from my Ubuntu workstation, and it does seem to work both from Ubuntu locally and from my remote machine. The only thing it displays is “8.6”, the Tkinter version number (I know you are using 8.5)
Since this most minimal example seems to work on my desktop, I suspect the issue has to do with Centos not having Tkinter installed properly or missing a windowing environment of some sort. Unfortunately, I can’t really help debug that, but if you post a bigger snippet of code I’m happy to try running that to validate it still works.
Hey @randyzwitch, thank you so much for your reply.
Thanks to your testing, i believe the main issue is due to the lack of a windowing environment in the CentOS server. It’s a command-line only server.
Though, and i admit my lack of knowledge in this field is huge, how does a lack of windowing environment in a CentOS server affect the user, considering that his environment has a windowing environment?
This is what those matplotlib answers are hinting at. Simplified, without a windowing server installed the Tkinter code on Centos says “hey graphics card, render this”, but that message goes unheard because nothing is there to listen. In a similar scenario with matplotlib, those answers are saying “you can re-route the output to this location, which would also render it”. The key is to figure out how you would accomplish this with Tkinter, which unfortunately I don’t know.
Thanks for your reply. I’ll try and ask my department to implement the windowing environemnt.