No module named pyLDAvis
Asked Answered
P

8

25

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?

Postdate answered 23/3, 2021 at 8:48 Comment(1)
Does this answer your question? ModuleNotFoundError: No module named 'pyLDAvis' in anaconda spyderBout
E
65

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)
Exhilarative answered 25/3, 2021 at 19:54 Comment(3)
Modifying name from gensim to 'gensim_models' works for me. ThankyouFrogfish
I get an error, ModuleNotFoundError: No module named 'pyLDAvis.gensim_models'Jori
#Creating Topic Distance Visualization import pyLDAvis.gensim_models as gensimvis pyLDAvis.enable_notebook() gensimvis.prepare(base_model,corpus,id2word) This is my code. I am using pyLDAvis 3.3.1Jori
J
15

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
Jaffna answered 16/5, 2021 at 4:56 Comment(0)
M
4

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
Mating answered 2/12, 2021 at 22:31 Comment(0)
W
2

Try this

!pip install pyLDAvis
import pyLDAvis.gensim_models

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

Warring answered 3/6, 2022 at 3:46 Comment(2)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Periotic
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Periotic
D
1

Please follow the below

import pyLDAvis.gensim_models as gensimvis
pyLDAvis.enable_notebook()
vis = gensimvis.prepare(lda_model, corpus, dictionary)
vis
Degradation answered 20/8, 2021 at 12:2 Comment(0)
E
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.

Epergne answered 22/2, 2022 at 23:15 Comment(0)
H
0

Update your pyLDAvis package to the latest version, which includes the pyLDAvis.gensim_models module. You can do this by running the command: pip install --upgrade pyLDAvis in your terminal.

Histoplasmosis answered 7/3, 2023 at 16:15 Comment(0)
C
0

The updated solution is:

import pyLDAvis
from gensim.models import LdaModel

pyLDAvis.enable_notebook()
vis = pyLDAvis.gensim.prepare(ldamodel, doc_term_matrix, dictionary)
pyLDAvis.display(vis)
Couloir answered 31/5, 2023 at 6:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.