Install & Compatibility
Where this runs
tested against v3.4.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
build_error
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 17.8s · import 4.028s · 422MB
440MB installed
● package 440MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
pyLDAvis
✓ import pyLDAvis
gensimvis
✓ from pyLDAvis import gensim_models as gensimvis
✗ import pyLDAvis.gensim as gensimvis
In 3.3.0, the gensim module was renamed to gensim_models to avoid conflicts. Old import path no longer works.
sklearnvis
✓ from pyLDAvis import sklearn_models as sklearnvis
✗ import pyLDAvis.sklearn as sklearnvis
In 3.4.0, the sklearn module was renamed to sklearn_models. Old path raises import error.
sklearn_models
✓ from pyLDAvis import sklearn_models
Do not use 'from pyLDAvis import sklearn' because 'sklearn' is the package itself.
Load a gensim LDA model, prepare interactive visualization, and save as HTML.
import pyLDAvis
import pyLDAvis.gensim_models as gensimvis
# Prepare data (example: using gensim LDA model)
# If using real API key, set it via os.environ
import os
api_key = os.environ.get('OPENAI_API_KEY', 'sk-...') # not used in this example
# Example with dummy data
from gensim.corpora import Dictionary
from gensim.models import LdaModel
# Create a simple corpus
docs = [['apple', 'orange', 'banana'], ['car', 'truck', 'bus']]
dictionary = Dictionary(docs)
corpus = [dictionary.doc2bow(doc) for doc in docs]
lda_model = LdaModel(corpus, num_topics=2, id2word=dictionary, passes=5)
# Prepare visualization
vis_data = gensimvis.prepare(lda_model, corpus, dictionary)
# Save to HTML file
pyLDAvis.save_html(vis_data, 'vis.html')
print('Visualization saved as vis.html')
Debug
Known issues
breakingModule renamed in v3.4.0: 'pyLDAvis.sklearn' no longer exists. Use 'pyLDAvis.sklearn_models'.fixChange import from 'pyLDAvis.sklearn' to 'pyLDAvis.sklearn_models'.
affects: >=3.4.0
breakingModule renamed in v3.3.0: 'pyLDAvis.gensim' no longer exists. Use 'pyLDAvis.gensim_models'.fixChange import from 'pyLDAvis.gensim' to 'pyLDAvis.gensim_models'.
affects: >=3.3.0
gotchaPandas 2.x changed .drop behavior; pyLDAvis 3.4.1 fixed this by adding axis=1 argument. If using older pyLDAvis with pandas 2.x, you'll get a ValueError.fixUpgrade pyLDAvis to 3.4.1 or later, or downgrade pandas to 1.x.
affects: <=3.4.0, pandas>=2.0
deprecatedsklearn's get_feature_names is removed in scikit-learn 1.0; pyLDAvis 3.4.0+ handles this. Older versions may raise AttributeError.fixUpgrade pyLDAvis to 3.4.0+ or use older scikit-learn.
affects: <=3.3.1, sklearn>=1.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pyLDAvis.sklearn'
In pyLDAvis 3.4.0, the sklearn module was renamed to sklearn_models.
fixUse 'from pyLDAvis import sklearn_models' instead.
ModuleNotFoundError: No module named 'pyLDAvis.gensim'
In pyLDAvis 3.3.0, the gensim module was renamed to gensim_models.
fixUse 'from pyLDAvis import gensim_models' instead.
ValueError: The parameter init='pca' cannot be used with metric='precomputed'.
When using pyLDAvis with sklearn LDA models, the default init='pca' is incompatible with some distance metrics.
fixWhen preparing sklearn LDA data, set init='random' or adjust metric parameter in the prepare call.
AttributeError: 'LdaModel' object has no attribute 'get_topics'
In older pyLDAvis versions, the API expects a method that doesn't exist in newer gensim.
fixUpgrade pyLDAvis to latest version (>=3.3.0) which uses updated gensim API.
Upgrade
Version history
3.4.1latest on PyPI · released Apr 23, 2023
Audit
Dependencies
pandasrequiredRequired for data manipulation, version ≥? (compatible with pandas 2.x)
gensimoptionalFor input from gensim LDA models
scikit-learnoptionalFor input from sklearn LDA models; note the module renamed in 3.4.0