简体   繁体   English

Jupyter Notebook:即使在 pip 安装后也找不到模块

[英]Jupyter Notebook: module not found even after pip install

I have a module installed in my Juyter notebook我的 Juyter 笔记本中安装了一个模块

!pip install gensim

Requirement already satisfied: gensim in /home/m.gawinecki/virtualenv/la-recoms/lib/python3.7/site-packages (3.8.2)

However, when I try to import it, it fails但是,当我尝试导入它时,它失败了

import gensim

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-e70e92d32c6e> in <module>
----> 1 import gensim

ModuleNotFoundError: No module named 'gensim'

It looks like it has been installed properly:看起来它已正确安装:

!pip list | grep gensim

gensim             3.8.2   

How can I fix it?我该如何解决?

Add your virtual environment as Python kernel in this way (Make sure it's activated):以这种方式将您的虚拟环境添加为 Python kernel(确保已激活):

(venv)
$ ipython kernel install --name "local-venv-kernel" --user

Now, you can select the created kernel "local-venv-kernel" when you start Jupyter notebook or lab.现在,当您启动 Jupyter notebook 或实验室时,您可以 select 创建 kernel “local-venv-kernel”。

You could check the installed libraries using this code in a notebook cell:您可以在笔记本单元格中使用此代码检查已安装的库:

!pip freeze 

Things that could help:可以帮助的事情:

  • if using virtualenv / conda or similar python environments: check if you are opening the notebook while being in the correct one.如果使用 virtualenv / conda 或类似的 python 环境:检查您是否在正确的环境中打开笔记本。 Check your console and activate the right one / deactivate the wrong ones检查您的控制台并激活正确的/停用错误的
  • uninstall and re-install the package thats causing the problem卸载并重新安装导致问题的 package
  • while installing the package check if other packages that you already had are affected, maybe there is some version problem and you need to remove or change other packages在安装 package 时检查您已经拥有的其他软件包是否受到影响,可能存在版本问题,您需要删除或更改其他软件包

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM