Reputation: 531
I trying to import gensim with
import gensim
but get the following error
ImportError Traceback (most recent call
last)
<ipython-input-5-50007be813d4> in <module>()
----> 1 import gensim
2 model = gensim.models.Word2Vec.load_word2vec_format('./model
/GoogleNews-vectors-negative300.bin', binary=True)
ImportError: No module named 'gensim'
I installed gensim in python. I use genssim for word2vec.
Upvotes: 52
Views: 135972
Reputation: 198
I had a similar problem and discovered that a environment variable was creating the problem.
When we start with
jupyter notebook
system-wide environment variables are used where gensim is not installed.
Solution: When we use (base) D:>python -m jupyter notebook
the SARC environment is initialised with plan python, which points to the location of the library.
so use
python -m jupyter notebook
if facing an issue with import where import gensim
is working fine in the terminal but failing in the notebook
Upvotes: 0
Reputation: 3
first, you have to run the command !pip install gensim==3.6.0
then run these commands
from gensim.models import KeyedVectors
from gensim.models import word2vec
model = KeyedVectors.load_word2vec_format('./model/GoogleNews-
vectors-negative300.bin', binary=True)
Upvotes: 0
Reputation: 59
If you have an anaconda environment running, try deactivating that and installing gensim again.
After doing it that way I was able to import it in jupyter notebook.
Upvotes: 0
Reputation: 4304
If you are trying to install genism
for the Jupyter notebook and all the above answers are not working, try installing genism
using conda-forge
channel
conda install -c conda-forge genism
Here I use the -c
flag to give the channel name. If channels are new to you I would like to refer you to this question on Stackoverflow
Upvotes: 0
Reputation: 1
The mirror link is slow guyz. Try it manually Download the gensim file from https://pypi.org/project/gensim/#files and extract it by Winrar then go inside the folder type python setup.py install it was success for me
Upvotes: 0
Reputation: 133
If you are using a virtual environment, check if gensim is installed with the following command:pip list
.
If it is not installed then install it: pip install -U gensim
or pip install gensim
.
Also if you are using Jupyter notebook, verify if gensim is install in the python kernel you are using.
Upvotes: 0
Reputation: 2370
i had this error because i ran "python" not "python3" i always do this from time to time.
Upvotes: 0
Reputation: 5075
Using pip inside Anaconda command prompt worked for me:
(base) C:\Users\ABC>pip install -U gensim
Upvotes: 0
Reputation: 2145
On Jupyter notebook, following worked for me
!python -m pip install -U gensim
Alternatively, run Anaconda prompt as administrator and execute the following
(base) C:\Windows\system32>conda install -c conda-forge gensim
Upvotes: 11
Reputation: 361
I did a pip install gensim --user
and it worked. The problem I was having with conda install gensim and pip -U install gensim was that it was not able to modify the environment variable at the end of the install.
Upvotes: 4
Reputation: 103
My solution is for Windows 10, Anaconda. Where I want to use gensim with Spyder.
Solution: Use Anaconda Navigator, and install package from there: Open Anaconda Navigator -> Environments (base) -> not installed (packages) -> (search for) gensim -> check the gensim option from the drop down list-> Press apply button -> (wait for a while, it will search other dependencies, then press the button one more time to install required package)
Scree shot of Anaconda Navigator
History: On anaconda command prompt, using conda command, I installed gensim. Every thing looks perfect but it was even not imported, "import gensim", in command prompt.
Upvotes: 3
Reputation: 566
As mentioned by @Burhan Khalid in the comments, don't name your file gensim.py as it will look in local folder first for gensim and consider it as what you are trying to import.
PS: I wrote this here as people tend to skip the comments. If it helped, please upvote the original comment.
Upvotes: 2
Reputation: 2187
If using Python3 be sure to use pip3 instead of pip for installing gensim.
Upvotes: 18
Reputation: 780
To Tanu's point, first guess would be you're not in the correct directory. Below is the first thing I would check.
import sys, os
# */site-packages is where your current session is running its python out of
site_path = ''
for path in sys.path:
if 'site-packages' in path.split('/')[-1]:
print(path)
site_path = path
# search to see if gensim in installed packages
if len(site_path) > 0:
if not 'gensim' in os.listdir(site_path):
print('package not found')
else:
print('gensim installed')
Upvotes: 1
Reputation: 1363
Does 'gensim' appear in the packages shown by the command pip freeze
? If not, you may not have activated the 'environment' with the necessary packages, in your working shell/IDE.
Upvotes: 0
Reputation: 1563
Install gensim using:
pip install -U gensim
Or, if you have instead downloaded and unzipped the source tar.gz package, then run:
python setup.py test
python setup.py install
Upvotes: 45