Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jupyter Notebook: module not found even after pip install

I have a module installed in my Juyter notebook

!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?

like image 539
dzieciou Avatar asked Jan 25 '23 03:01

dzieciou


2 Answers

Add your virtual environment as Python kernel in this way (Make sure it's activated):

(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.

You could check the installed libraries using this code in a notebook cell:

!pip freeze 
like image 128
negas Avatar answered Feb 05 '23 06:02

negas


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. Check your console and activate the right one / deactivate the wrong ones
  • uninstall and re-install the package thats causing the problem
  • 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
like image 22
gustavz Avatar answered Feb 05 '23 06:02

gustavz