问题描述
此错误:
TclError: no display name and no $DISPLAY environment variable
当我试图在Google Colab(协作Jupyter笔记本)中运行Python 3.6程序时出现了.我正在Windows 10计算机上的Chrome中运行Colab.我已经在Stack Overflow的其他线程中看到了此错误,但是在Colab的环境中却没有看到此错误,并且以前发布的解决方案要么不适用,要么似乎不起作用.
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 *
请注意,要使tkinter导入正常工作,我必须在其他Colab单元中发出以下指令:
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
推荐答案
问题是您尝试使用的 tkinter
.
Tk通常会为您的界面创建GUI(如新窗口).但是Colab是在云中的Web服务器上运行的.它无法在您的计算机上打开一个窗口.您只能通过笔记本界面与之交互.
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.
您需要限制交互作用以不使用GUI.或通过笔记本将其更改为基于Web的.您要运行哪种程序?
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?
这篇关于TclError:Google Colab中没有显示名称,也没有$ DISPLAY环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!