Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

python - TclError: no display name and no $DISPLAY environment variable in Google Colab

This error:

TclError: no display name and no $DISPLAY environment variable

arose when I tried to run a Python 3.6 program inside Google Colab (collaborative Jupyter notebooks). I am running Colab in Chrome on a Windows 10 machine. I've seen this error reported in other threads on Stack Overflow but not in the context of Colab, and previously posted solutions either don't apply or don't seem to work.

My code begins like this:

from matplotlib.pyplot import *
from matplotlib.widgets import *
from math import *
from random import *
from numpy import *
from tkinter import *

Note that to get the import of tkinter to work, I had to issue the following instruction in a different Colab cell:

!apt-get install python3-tk
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The problem is the tkinter that you are trying to use.

Tk will normally create GUI (like a new window) for your interface. But Colab is run on the web server in the cloud. It can't open a window on your machine. You can only interact with it through notebook interface.

You need to limit the interaction not to use GUI. Or change them to web-based through notebook. What kind of program are you trying to run?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...