没有名为“gensim"的模块,但已经安装了它 [英] No module named 'gensim' but already installed it

查看:50
本文介绍了没有名为“gensim"的模块,但已经安装了它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了这个错误问题,我在基本(root)环境的 jupyter notebook 中运行了这个脚本,日志说已经安装了 gensim 库,我已经运行了命令 !pip install gensim 在我导入它之前,但它仍然无法导入,错误说 ModuleNotFoundError: No module named 'gensim'

i'm having this error problem, i have ran this script in jupyter notebook in base (root) environment, the log said that gensim library has been installed and i have run the command !pip install gensim before i import it, but it still can not be imported, and the error said ModuleNotFoundError: No module named 'gensim'

!pip install gensim
import gensim
from gensim.models import KeyedVectors
model = KeyedVectors.load('model_fasttext2.vec')
model.vector_size
------------------------------------------------------------------------
Requirement already satisfied: gensim in c:usersip-03anaconda3libsite-packages (3.8.1)
Requirement already satisfied: scipy>=0.18.1 in c:usersip-03anaconda3libsite-packages (from gensim) (1.4.1)
Requirement already satisfied: six>=1.5.0 in c:usersip-03anaconda3libsite-packages (from gensim) (1.14.0)
Requirement already satisfied: smart-open>=1.8.1 in c:usersip-03anaconda3libsite-packages (from gensim) (1.9.0)
Requirement already satisfied: numpy>=1.11.3 in c:usersip-03anaconda3libsite-packages (from gensim) (1.18.1)
Requirement already satisfied: boto>=2.32 in c:usersip-03anaconda3libsite-packages (from smart-open>=1.8.1->gensim) (2.49.0)
Requirement already satisfied: boto3 in c:usersip-03anaconda3libsite-packages (from smart-open>=1.8.1->gensim) (1.12.3)
Requirement already satisfied: bz2file in c:usersip-03anaconda3libsite-packages (from smart-open>=1.8.1->gensim) (0.98)
Requirement already satisfied: requests in c:usersip-03anaconda3libsite-packages (from smart-open>=1.8.1->gensim) (2.22.0)
Requirement already satisfied: s3transfer<0.4.0,>=0.3.0 in c:usersip-03anaconda3libsite-packages (from boto3->smart-open>=1.8.1->gensim) (0.3.3)
Requirement already satisfied: botocore<1.16.0,>=1.15.3 in c:usersip-03anaconda3libsite-packages (from boto3->smart-open>=1.8.1->gensim) (1.15.3)
Requirement already satisfied: jmespath<1.0.0,>=0.7.1 in c:usersip-03anaconda3libsite-packages (from boto3->smart-open>=1.8.1->gensim) (0.9.4)
Requirement already satisfied: certifi>=2017.4.17 in c:usersip-03anaconda3libsite-packages (from requests->smart-open>=1.8.1->gensim) (2019.11.28)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in c:usersip-03anaconda3libsite-packages (from requests->smart-open>=1.8.1->gensim) (3.0.4)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:usersip-03anaconda3libsite-packages (from requests->smart-open>=1.8.1->gensim) (1.25.8)
Requirement already satisfied: idna<2.9,>=2.5 in c:usersip-03anaconda3libsite-packages (from requests->smart-open>=1.8.1->gensim) (2.8)
Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in c:usersip-03anaconda3libsite-packages (from botocore<1.16.0,>=1.15.3->boto3->smart-open>=1.8.1->gensim) (2.8.1)
Requirement already satisfied: docutils<0.16,>=0.10 in c:usersip-03anaconda3libsite-packages (from botocore<1.16.0,>=1.15.3->boto3->smart-open>=1.8.1->gensim) (0.15.2)

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-10-ee4a48d372cd> in <module>
      1 get_ipython().system('pip install gensim')
----> 2 import gensim
      3 from gensim.models import KeyedVectors
      4 model = KeyedVectors.load('model_fasttext2.vec')
      5 model.vector_size

ModuleNotFoundError: No module named 'gensim'

有没有人可以帮助解决这个问题?我将非常感谢您的帮助,这将有助于我的论文工作,感谢您的关注

Is there anyone who can help this problem? i will really appreciate your help, it will help my thesis work, thank you for your attention

推荐答案

可能是您的 jupyter 实验室运行的是基础内核,而不是虚拟环境的内核.

It may be that your jupyter lab maybe running the base kernel and not the kernel of the virtual environment.

执行以下检查:

import sys
sys.executable

进入我的笔记本并得到结果

into my notebook and got the result

'/anaconda3/bin/python'

如果你得到上面的而不是下面的,那就意味着你使用了错误的内核.

If you get the above instead of the below then that means you're using the wrong kernel.

'/anaconda3/envs/myenv/bin/python'

您可以通过为您的新环境创建一个新的 iPython 内核来解决它.阅读更多此处.>

You can solve it by creating a new iPython kernel for your new environment. Read more here.

conda install -n myenv ipython
conda activate myenv
python -m ipykernel install --user --name myenv --display-name "Python (myenv)"
```Then, to run Jupyter Lab in the new environment:

这篇关于没有名为“gensim"的模块,但已经安装了它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆