'gensim error : no module named gensim
I trying to import gensim.
I have the following code
import gensim
model = gensim.models.Word2Vec.load_word2vec_format('./model/GoogleNews-
vectors-negative300.bin', binary=True)
I got 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.
Solution 1:[1]
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
Solution 2:[2]
If using Python3 be sure to use pip3 instead of pip for installing gensim.
Solution 3:[3]
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
Solution 4:[4]
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.
Solution 5:[5]
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
- Repeat above for word2vec
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.
- Bonus: Same is true for tensorflow
Solution 6:[6]
import model gensim python3x:
pip install gensim
Solution 7:[7]
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.
Solution 8:[8]
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')
Solution 9:[9]
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.
Solution 10:[10]
Using pip inside Anaconda command prompt worked for me:
(base) C:\Users\ABC>pip install -U gensim
Solution 11:[11]
i had this error because i ran "python" not "python3" i always do this from time to time.
Solution 12:[12]
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.
Solution 13:[13]
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
Solution 14:[14]
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
Solution 15:[15]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow