Couldn't connect to display":10.0" Error on tkinter

Asked 2 years ago, Updated 2 years ago, 102 views

When I connected vnc from win10 to ubuntu18.04 LTS, I received the following error:

root@kawasakih2sx-desktop:/home/takumii/ss #python test2.py
No protocol specified
No protocol specified
Traceback (most recent call last):
  File "test2.py", line 7, in <module>
    plt.scatter(x,y,s=20)
  File"/root/.pyenv/versions/3.6.8/lib/python 3.6/site-packages/matplotlib/pyplot.py", line 2858, inscatter
    __ret=gca().scatter(
  File"/root/.pyenv/versions/3.6.8/lib/python 3.6/site-packages/matplotlib/pyplot.py", line 935, ingca
    return gcf().gca(**kwargs)
  File"/root/.pyenv/versions/3.6.8/lib/python 3.6/site-packages/matplotlib/pyplot.py", line 578, ingcf
    return figure()
  File"/root/.pyenv/versions/3.6.8/lib/python 3.6/site-packages/matplotlib/pyplot.py", line 525, configure
    **kwargs)
  File"/root/.pyenv/versions/3.6.8/lib/python 3.6/site-packages/matplotlib/backend_bases.py", line 3218, in new_figure_manager
    return cls.new_figure_manager_given_figure(num,fig)
  File"/root/.pyenv/versions/3.6.8/lib/python 3.6/site-packages/matplotlib/backends/_backend_tk.py", line 1008, in new_figure_manager_given_figure
    window=Tk.Tk (className="matplotlib")
  File"/root/.pyenv/versions/3.6.8/lib/python 3.6/tkinter/__init__.py", line 2023, in_init__
    self.tk=_tkinter.create(screenName,baseName,className,interactive,wantobjects,useTk,sync,use)
_tkinter.TclError: couldn't connect to display": 10.0"

The contents of test2.py are as follows:

import matplotlib.pyplot as plt
import numpy as np

x = np.random.randn(60)
y=np.random.randn(60)

plt.scatter(x,y,s=20)

I would appreciate it if you could let me know how to solve this problem.
Thank you for your cooperation.

*Additional information

I mentioned a vnc connection from win10 to Ubuntu, but to be exact, I am using a remote desktop with a vnc connection.
Thank you for your cooperation.

python tkinter

2022-09-29 21:22

1 Answers

The GUI display on Ubuntu(=Linux) uses the X server mechanism, so to launch the GUI
The environment variable DISPLAY must be set to which display the window.

It's a bit complicated because you're using VNC, but if you want to run the program on Ubuntu and the GUI on Ubuntu, try running the Python program after setting the environment variable DISPLAY as follows:

$export DISPLAY=":0.0"

Note:
Environment Variables:DISPLAY:UNIX/Linux Rooms


2022-09-29 21:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.