简体   繁体   English

没有名为 pyLDAvis 的模块

[英]No module named pyLDAvis

I can't import pyLDAvis.我无法导入 pyLDAvis。

It is installed but for some reason, I can not import it.它已安装,但由于某种原因,我无法导入它。

I tried我试过了

conda update anaconda

pip install --upgrade pip

pip install --upgrade jupyter notebook

pip install pyLDAvis

Installing pyLDAvis returns the message 'requirement already satisfied'.安装 pyLDAvis 会返回消息“要求已满足”。 So I tried uninstalling and reinstalled the package but still doesn't work.所以我尝试卸载并重新安装 package 但仍然无法正常工作。 This never happened with any other packages.任何其他软件包都不会发生这种情况。

How can I solve this problem?我怎么解决这个问题?

The pyLDAvis gensim name changed. pyLDAvis gensim 名称已更改。 When I use gensim_models rather than gensim the interactive viz works.当我使用gensim_models而不是gensim时,交互式即可以工作。

The 'gensim_models' name is in the latest commit to bmabey's repo . 'gensim_models' 名称在bmabey 的 repo的最新提交中。

import pyLDAvis
import pyLDAvis.gensim_models as gensimvis
pyLDAvis.enable_notebook()

# feed the LDA model into the pyLDAvis instance
lda_viz = gensimvis.prepare(ldamodel, corpus, dictionary)

Following code worked for me and I'm using Google Colaboratory.以下代码对我有用,我正在使用 Google Colaboratory。

!pip install pyLDAvis

import pyLDAvis
import pyLDAvis.gensim_models

pyLDAvis.enable_notebook()
vis = pyLDAvis.gensim_models.prepare(ldamodel, doc_term_matrix, dictionary)
vis

If you are working in jupyter notebook (python vs3.3.0)如果您正在使用 jupyter notebook (python vs3.3.0)

"the No module named 'pyLDAvis.gensim'" “名为 'pyLDAvis.gensim' 的 No 模块”

error can be solved using:可以使用以下方法解决错误:

import pyLDAvis.gensim_models

instead of:代替:

import pyLDAvis.gensim

Please follow the below请按照以下

import pyLDAvis.gensim_models as gensimvis
pyLDAvis.enable_notebook()
vis = gensimvis.prepare(lda_model, corpus, dictionary)
vis

Even after viewing your answers,即使在查看了您的答案之后,

I modified my code to我将代码修改为

import pyLDAvis.gensim_models as gensimvis

pyLDAvis.enable_notebook()

gensimvis.prepare(base_model,corpus,id2word)

I am still getting an error,我仍然收到错误,

The Error is as below.错误如下。 I am using the latest version of pyLDAvis 3.3.1我正在使用最新版本的 pyLDAvis 3.3.1

在此处输入图像描述

The pip installation may not agree with Anaconda. pip安装可能与 Anaconda 不一致。 It is better to use conda installation.最好使用conda安装。

conda install -c conda-forge pyldavis

Then it should work fine with Anaconda Python.然后它应该可以与 Anaconda Python 一起正常工作。

Try this尝试这个

!pip install pyLDAvis
import pyLDAvis.gensim_models

This should work.这应该有效。 I faced the same issue and it worked for me我遇到了同样的问题,它对我有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM