我想绘制图(内联)的nltk
内jupyter-notebook
。但得到的错误:使用tkinter为nltk绘制jupyter笔记本内
TclError: no display name and no $DISPLAY environment variable
我已经尝试设置$DISPLAY
为不同的值:
$env DISPLAY=0.0
# or
$env DISPLAY=inline
# or
$env DISPLAY=
,但得到的错误(或类似):
TclError: couldn't connect to display "0.0"
这里是我的代码https://github.com/hyzhak/nltk-experiments/blob/master/main.ipynb最后细胞。
环境:官方anaconda3码头 - continuumio/anaconda3:4.4.0
https://github.com/ContinuumIO/docker-images。里面有nltk==3.2.3
。
Python 3.6.1 |Anaconda 4.4.0 (64-bit)| (default, May 11 2017, 13:09:58)
Type "copyright", "credits" or "license" for more information.
IPython 5.3.0 -- An enhanced Interactive Python.
我怎么能解决这个错误,在线nltk
图形jupyter notebook
里面?
更新1
http://www.nltk.org/_modules/nltk/draw/tree.html#draw_trees根据NLTK树的来源绘制它使用tkinter
。
更新2
我也问过官方NLTK的github仓库同样的问题https://github.com/nltk/nltk/issues/1765
更新3
我认为错误的原因可能是无头的主机(搬运工)。我已经安装了xvfb
,但似乎已经足够了。
RUN apt-get install -y xvfb
解决方案
我认为xvfb
默认情况下推出的,但应当明确的运行。所以在我启动之后,我可以制作nltk树形图的截图。
嘿,你怎么跑'xvfb'明确?我运行了'Xvfb:1 -screen 0 800x600x16'命令,但仍然收到相同的错误。 –
我已经将它作为守护进程启动。 –