简体   繁体   中英

No module named pyLDAvis

I can't import 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'. So I tried uninstalling and reinstalled the package but still doesn't work. This never happened with any other packages.

How can I solve this problem?

The pyLDAvis gensim name changed. When I use gensim_models rather than gensim the interactive viz works.

The 'gensim_models' name is in the latest commit to bmabey's 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.

!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)

"the No module named 'pyLDAvis.gensim'"

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

在此处输入图像描述

The pip installation may not agree with Anaconda. It is better to use conda installation.

conda install -c conda-forge pyldavis

Then it should work fine with Anaconda Python.

Try this

!pip install pyLDAvis
import pyLDAvis.gensim_models

This should work. I faced the same issue and it worked for me

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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