I have a bIg data platform. On that I install Anaconda. When I ssh to my account on the platform and open up a Python interpreter in terminal it works fine when I import the gensim library. I had earlier installed this library using
Conda install gensim
$ python
Python 2.7.12 |Anaconda 2.5.0 (64-bit)| (default, Jul 2 2016, 17:42:40)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import gensim
/home/anaconda2/lib/python2.7/site-packages/gensim/utils.py:1015: UserWarning: Pattern library is not installed, lemmatization won't be available.
warnings.warn("Pattern library is not installed, lemmatization won't be available.")
If you see it does import the library (just gives some warning for Pattern library). However when I open up Jupyter notebook and try to import the same library there it gives the following:
In [11]:
import gensim
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-11-0539d76422c6> in <module>()
----> 1 import gensim
ImportError: No module named gensim
Am not sure why the same library which is installed is not working in Jupyter. Please note that when I do
pip list
it shows me all the libraries and it has gensim there.
pip list
will not show you conda modules try conda list
to ensure you have the gensim module installed
EDIT:
Also ensure your kernelspec and the python interpreter are pointing to the same enviroment
http://jupyter-client.readthedocs.io/en/stable/api/kernelspec.html
这个问题很老,但由于谷歌把我放在这里,对于其他人,我不得不为那个 conda 环境安装 jupyter,因为它也是全局安装的,没有看到我的 env 包。
Probably you're running Jupyter with a different Python interpreter. See what this prints in the notebook:
import sys
sys.path
Do the directories listed look similar or different from the ones you saw when starting Python in the terminal?
Execute in command prompt:
pip install gensim
will solve the problem "No module named gensim"
For some reason, after installing gensim in a virtual environment with
conda install -c conda-forge gensim
You have to re-install jupyter with:
conda install jupyter
Otherwise jupyter will open the kernel and the sys.path
of the base environment, and thus will not recognize gensim and import gensim
will not work.
I have no idea why is that, maybe the gensim conda package is broken.
EDIT:
If jupyter is installed with the previous command, you have to force reinstallation as follows:
conda update jupyter --force-reinstall --no-deps
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.