TclError:Google Colab 中没有显示名称和 $DISPLAY 环境变量 [英] TclError: no display name and no $DISPLAY environment variable in Google Colab

查看:52
本文介绍了TclError:Google Colab 中没有显示名称和 $DISPLAY 环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个错误:

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.

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

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.或者通过笔记本将它们更改为基于网络的.你想运行什么样的程序?

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 环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆