'display_formatter' Python 中的属性错误

'display_formatter' attribute error in Python

我正在开发一个主题建模脚本,该脚本使用 gensim 包创建基于文档集合的模型。

在准备使用 pyLDAvis 包可视化模型时,我 运行 遇到了这个错误:

import pyLDAvis
pyLDAvis.enable_notebook()

Traceback (most recent call last):
  File "/dev2.py", line 2, in <module>
    pyLDAvis.enable_notebook()
  File "/Users/username/Library/Python/3.6/lib/python/site-packages/pyLDAvis/_display.py", line 311, in enable_notebook
    formatter = ip.display_formatter.formatters['text/html']
AttributeError: 'NoneType' object has no attribute 'display_formatter'

enable_notebook功能仅在您使用笔记本时使用。如果您正在编写将可视化输出为 HTML 文档的脚本,那么您不需要(也不应该)调用该函数。相反,我认为您需要使用的只是 prepare 和 save_html 函数。