【发布时间】:2018-06-20 18:49:34
【问题描述】:
我在 Ubuntu 16.04 上使用 PyCharm 2017.2.3 和 python 2.7。我在尝试使用 matplotlib 将一个简单的代码绘制为下一个时遇到了问题。
from matplotlib import pyplot as plt
import matplotlib.image as mpimg
image = mpimg.imread("chelsea-the-cat.png")
plt.imshow(image)
plt.show()
显然没有错误或警告,只是正在运行的脚本卡住了。但是当使用调试时,调试控制台会打印出这样的:
/home/esromerom/.virtualenvs/cv/bin/python /opt/pycharm-2017.2.3/helpers/pydev/pydevd.py --multiproc
--qt-support=auto --client 127.0.0.1 --port 45601 --file
"/media/esromerom/TOSHIBA EXT/grado/cv/image.py" pydev debugger: process 14506 is connecting
Connected to pydev debugger (build 172.3968.37)
Failed to enable GUI event loop integration for 'tk'
Traceback (most recent call last):
File "/opt/pycharm-2017.2.3/helpers/pydev/pydev_ipython/matplotlibtools.py", line 31, in do_enable_gui
enable_gui(guiname)
File "/opt/pycharm-2017.2.3/helpers/pydev/pydev_ipython/inputhook.py", line 528, in enable_gui
return gui_hook(app)
File "/opt/pycharm-2017.2.3/helpers/pydev/pydev_ipython/inputhook.py", line 278, in enable_tk
app = _TK.Tk()
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1818, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
TclError: couldn't connect to display "True"
Backend TkAgg is interactive backend. Turning interactive mode on.
TkAgg
我已经尝试过针对类似问题的推荐解决方案,但脚本仍然没有显示任何内容。 (检查 matplotlib 后端,重新安装 tk 库,重新安装 matplotlib,在运行/调试配置中添加“DISPLAY=True”,...)
有人知道它是如何发生的吗?
【问题讨论】:
-
对不起,我不会有用的。同样的事情在 Ubuntu 18.04 LTS 中也发生在我身上。很高兴知道我不是唯一一个,但很遗憾似乎没有解决这个问题的方法。
标签: python user-interface matplotlib pycharm ubuntu-16.04