TclError: no display name and no $DISPLAY environment variable in google's colab

£可爱£侵袭症+ 提交于 2020-06-21 05:06:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!