Home:ALL Converter>ModuleNotFoundError: No module named 'gensim'

ModuleNotFoundError: No module named 'gensim'

Ask Time:2019-05-22T01:28:54         Author:Software Dev

Json Formatter

My goal is to import gensim in Python 3 on Windows.

I am using Python 3.7.2 (checked by running python -V in Windows command prompt). I installed gensim by running pip install gensim. I checked the installation by running pip freeze, and saw the line gensim==3.7.3.

Then, I ran the command py to enter the interactive python mode (still in Windows command prompt). I ran the line import gensim and got the following output:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'gensim'

I also tried from gensim import test and got the following output:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'gensim'

Any suggestions? How do I install gensim on Windows with Python 3? How do I test gensim?

Author:Software Dev,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/56243568/modulenotfounderror-no-module-named-gensim
Sayali Sonawane :

In Mac, open anaconda navigator, Click on 'Open Terminal option'. If you are using Windows, Run anaconda prompt as administrator and run the following command:\n\nconda install -c conda-forge gensim",
2020-09-21T16:47:50
Ashok Rayal :

I think you have installed it using normal cmd, so it may have installed it on python2.x. Install it with anaconda prompt.\n\nLet me know if it worked for you.",
2019-05-21T17:33:01
Orhan Celik :

I got the same error after installing gensim in Anaconda. It worked only after I re-started the Anaconda: by exiting it, and re-opening it via the command prompt. I wanted to share this experience since someone else may meet the same issue.",
2019-05-24T19:59:55
wovano :

To understand why this happens, you must know how Windows finds executables to run, and how the Python software is installed.\n\nWhen running a command, Windows searches for an executable in the environment variable PATH. It executes the first one found.\npython.exe is installed in <PYTHON_INSTALL_DIR> (e.g. C:\\Python\\3.7).\npip.exe and other Python tools (e.g. pylint, virtualenv, pycrust, etc.) are installed in <PYTHON_INSTALL_DIR>\\Scripts.\npy.exe is installed in your Windows system directory (e.g. C:\\Windows).\npython and pip commands use the modules found in the directory their installed in, they do not look at PATH.\n\nSo, let's say you have the following Python versions:\nC:\\Python\\2.7\nC:\\Python\\3.6\nC:\\Python\\3.7\n\nand your PATH environment contains the following directories:\nC:\\Python\\2.7\nC:\\Python\\3.6\\Scripts\n\nthen, see the following output:\nC:\\>python -V\nPython 2.7.16\n\nC:\\>pip -V\npip 19.1.1 from c:\\python\\3.6\\lib\\site-packages\\pip (python 3.6)\n\nC:\\>py -V\nPython 3.7.3\n\nSo, when running pip, it is possible that the packages are installed in another Python version then the version you'll get when running python.\nTo see which versions are (correctly) installed on your system, run py -0p. Example output:\nC:\\>py -0p\nInstalled Pythons found by py Launcher for Windows\n -3.7-64 C:\\Python\\3.7-64\\python.exe *\n -3.7-32 C:\\Python\\3.7-32\\python.exe\n -3.6-64 C:\\Python\\3.6-64\\python.exe\n -2.7-64 C:\\Python\\2.7-64\\python.exe\n -2.7-32 C:\\Python\\2.7-32\\python.exe\n\nGeneral solution (for Windows)\nThe best thing is not to rely on your system PATH. Use the py launcher to select the version you want. To run the pip module corresponding to the Python version you want to use, start pip as a module instead of executable.\nSo instead of:\npip install <package>\n\nrun:\npy -3.6 -m pip install <package>\n",
2019-05-24T20:24:35
Vasu Deo.S :

Here's My hypothesis towards your situation, since your OS is able to recognize both python and py commands in commandline, this may mean that you have two separate versions of python installed.\n\nSince, as you mentioned that python -V shows gensim as an installed module. Try opening python interactive interpreter via command python instead of py, and import gensim module in it.\n\nC:\\Users> Python\nPython 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 21:26:53) [MSC v.1916 32 bit (Intel)] \non win32\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n>>> import gensim\n\n\nsee if that works.\n\nP.S.\n\nI would not recommend having two different compiler versions on a single OS as it creates a lot of commotion, and create incompatibility issues with program's made on one compiler with the other. And makes problems (like you mentioned) a lot more prevalent.",
2019-05-21T17:47:28
yy