python代码在linux终端中执行报错:Unable to init server: Could not connect: Connection refused时间:2023-03-09 08:15:45 python代码在linux终端中执行时报错: Unable to init server: Could not connect: Connection refused Unable to init server: 无法连接: Connection refused 解决办法: 在要执行的python文件里加入以下两句代码: 切记:在最开头添加。 import matplotlib matplotlib.use('Agg')