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

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

问题描述

我遇到此错误问题,我已经在基本(根)环境中的jupyter笔记本中运行了此脚本,日志中说gensim库已安装,并且我已运行命令!pip install gensim 在我导入它之前,但是它仍然不能导入,并且错误提示 ModuleNotFoundError:没有名为'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:\users\ip-03\anaconda3\lib\site-packages (3.8.1)
Requirement already satisfied: scipy>=0.18.1 in c:\users\ip-03\anaconda3\lib\site-packages (from gensim) (1.4.1)
Requirement already satisfied: six>=1.5.0 in c:\users\ip-03\anaconda3\lib\site-packages (from gensim) (1.14.0)
Requirement already satisfied: smart-open>=1.8.1 in c:\users\ip-03\anaconda3\lib\site-packages (from gensim) (1.9.0)
Requirement already satisfied: numpy>=1.11.3 in c:\users\ip-03\anaconda3\lib\site-packages (from gensim) (1.18.1)
Requirement already satisfied: boto>=2.32 in c:\users\ip-03\anaconda3\lib\site-packages (from smart-open>=1.8.1->gensim) (2.49.0)
Requirement already satisfied: boto3 in c:\users\ip-03\anaconda3\lib\site-packages (from smart-open>=1.8.1->gensim) (1.12.3)
Requirement already satisfied: bz2file in c:\users\ip-03\anaconda3\lib\site-packages (from smart-open>=1.8.1->gensim) (0.98)
Requirement already satisfied: requests in c:\users\ip-03\anaconda3\lib\site-packages (from smart-open>=1.8.1->gensim) (2.22.0)
Requirement already satisfied: s3transfer<0.4.0,>=0.3.0 in c:\users\ip-03\anaconda3\lib\site-packages (from boto3->smart-open>=1.8.1->gensim) (0.3.3)
Requirement already satisfied: botocore<1.16.0,>=1.15.3 in c:\users\ip-03\anaconda3\lib\site-packages (from boto3->smart-open>=1.8.1->gensim) (1.15.3)
Requirement already satisfied: jmespath<1.0.0,>=0.7.1 in c:\users\ip-03\anaconda3\lib\site-packages (from boto3->smart-open>=1.8.1->gensim) (0.9.4)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\ip-03\anaconda3\lib\site-packages (from requests->smart-open>=1.8.1->gensim) (2019.11.28)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in c:\users\ip-03\anaconda3\lib\site-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:\users\ip-03\anaconda3\lib\site-packages (from requests->smart-open>=1.8.1->gensim) (1.25.8)
Requirement already satisfied: idna<2.9,>=2.5 in c:\users\ip-03\anaconda3\lib\site-packages (from requests->smart-open>=1.8.1->gensim) (2.8)
Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in c:\users\ip-03\anaconda3\lib\site-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:\users\ip-03\anaconda3\lib\site-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天全站免登陆