python 错误_tkinter.TclError: no display name and no $DISPLAY environment variable 问题的解决

当运行一个需要绘图的python程序,在windows上运行正常的情况下,放到linux环境上往往会出现错误:

_tkinter.TclError: no display name and no $DISPLAY environment variable   如下图所示:

于是经常一些列网上的得出自己的解决方案如下:

1.完善相应的库文件

在ubuntu的情况下:

(1)apt install python3-tk

(2)apt install tk-dev

在centos的情况下:

(1)yum -y install python3-tk

(2)yum -y install tk-dev  如果这个错误就运行:yum -y install tk*

2.安装相关的辅助软件Xming,配合Xshell+Xming可得出制图

(1)下载Xming官网下载软件

运行Xming 

(2)修改Xshell 设置

在设置中找到 隧道 修改 如下图:

最后重新连接下xshell即可。再次运行可以得出图片:

猜你喜欢

转载自blog.csdn.net/qq_24036403/article/details/86535401