Tk Initialization Failed: No Display Name and No $Display Environment Variable

TkInter error: no display name and no $DISPLAY environment variable

You're apparently trying to do this with repl.it's "Python", which doesn't support the display that tkinter needs. They do offer a separate "Tkinter" option, although it's quite far down the list of languages. Here's a shortcut: https://repl.it/languages/tkinter

There you don't get that error. In order to actually get the window shown, you'll have to also add this under your current code:

root.mainloop()

Demo

_tkinter.TclError: no display name and no $DISPLAY environment variable

Matplotlib chooses Xwindows backend by default.
You need to set matplotlib to not use the Xwindows backend.

Add this code to the start of your script (before importing pyplot) and try again:

import matplotlib
matplotlib.use('Agg')

Or add to .config/matplotlib/matplotlibrc line backend: Agg to use non-interactive backend.

echo "backend: Agg" > ~/.config/matplotlib/matplotlibrc

Or when connect to server use ssh -X remoteMachine command to use Xwindows.

Also you may try to export display: export DISPLAY=mymachine.com:0.0.

For more info: https://matplotlib.org/faq/howto_faq.html#matplotlib-in-a-web-application-server

Cannot launch Git GUI using Cygwin on Windows

Cygwin's gitk and Git GUI require X11. This means you need to install some of the Cygwin X11 packages and set them up to be able to open the GUI.

This should get you up and running:

  1. Run the Cygwin installer again (download the relevant setup-*.exe again if you need to).
  2. At the package list, select to install "xinit" under the X11 category. Click next, accept all the dependencies, and install.
  3. In the Windows Start menu, you should have a new group: Cygwin-X. From there, run XWin Server.
  4. In your Cygwin shell, run export DISPLAY=:0.0.

You'll need to repeat step 3 every time you reboot your computer, and step 4 every time you open a new Cygwin shell (or just run echo "export DISPLAY=:0.0" >>~/.profile to have it run automatically whenever you create a new shell).

In the comments, it seems some people are getting errors stating 'couldn't connect to display ":0.0"'. If you get that, mouse over the X that should have appeared in your system tray (you may need to click the little up icon if the X icon has been hidden); the pop-up title should say something like "Cygwin/X Server:1.0". Use that ":1.0" (or whatever you see) as the value for DISPLAY in step 4, rather than ":0.0", making sure to include the colon.

If you have any other problems starting the X server, you will probably find you have a file called ~/.xsession-errors; check out the contents of that for what's going wrong. Also check whether you have a ~/.startxwinrc file, and try deleting it and seeing if that fixes the problem.

For the interested, the reason the X11 packages aren't installed automatically is that they're not technically needed: it's possible through somewhat convoluted means to use a different X11 server than the one Cygwin installs when you install the "xinit" package.

How can I run Gitk on WSL 2?

You can install and run gitk straight from ubuntu terminal on Windows 11, using apt install.

I've just followed the steps from the following post and it worked:
https://learn.microsoft.com/en-us/windows/wsl/tutorials/gui-apps

I had to update not only the graphic driver but also the WSL.

Now, I can use either gitk or any linux app on Windows 11.



Related Topics



Leave a reply



Submit