Kate S.D.
Kate S.D.

Reputation: 105

Gensim package installation/word2vec not recognised

from gensim.models import Word2Vec

results in the following error ImportError: cannot import name 'Word2Vec' from 'gensim.models' (unknown location)

from gensim.models.word2vec import Word2Vec

results in the same error

After deleting all conda installations of this package, pip uninstalling gensim, pip installing gensim and pip install --upgrade gensim, I can finally do

import gensim but when I try to use gensim.models.Word2Vec it results in the error: AttributeError: module 'gensim.models' has no attribute 'Word2Vec'

Edit: updated Numpy and Scipy as well

Note: I am using a jupyter notebook that I run from my local machine. I have not had this problem using Pycharm where I was running gensim from a conda env (but I'm working on a group project in notebook so it would be nice if I didn't constantly have to copy paste between these 2 workspaces...)

Any help would be appreciated

Upvotes: 0

Views: 2037

Answers (1)

Nicolai B. Thomsen
Nicolai B. Thomsen

Reputation: 884

First, try to restart your kernel after the installation and see if it works. Then, check that your are in the right virtual environment. Then, please check you gensim version. In a notebook cell run

import gensim
gensim.__version__ # should be 4.1.2. If it's not update via pip.

You can also manually inspect if gensim.models.word2vec is actually there. In a notebook cell run

gensim.__path__

and go to the folder. Here you can see if there's indeed a folder named models and a script named word2vec. If not, there's something wrong with your installation. Hope this helps a bit.

Upvotes: 1

Related Questions