我想繪製圖(內聯)的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'命令,但仍然收到相同的錯誤。 –
我已經將它作爲守護進程啓動。 –