问题
This error:
TclError: no display name and no $DISPLAY environment variable
arose when I tried to run a Python 3.6 program inside google's new colab facility (collaborative Jupyter notebooks). I am running colab in Chrome on a Windows 10 machine. I've seen this error reported in other threads on stackoverflow 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
回答1:
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?
来源:https://stackoverflow.com/questions/49478228/tclerror-no-display-name-and-no-display-environment-variable-in-googles-colab