14

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?

dzieciou
  • 4,049
  • 8
  • 41
  • 85

2 Answers2

12

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 
negas
  • 841
  • 12
  • 10
  • 1
    Awesome, thanks. Only this solution worked for me in mac. – Karthik Arumugham Jun 10 '21 at 02:23
  • 1
    This suggestion https://stackoverflow.com/questions/42321784/jupyter-modulenotfounderror-no-module-named-matplotlib also works, but less intrusive for ongoing updating an existing kernel. – Yu Shen Aug 12 '22 at 21:24
  • I agree. However, I prefer to keep clearly separated and identified virtual environments. It's a good practice. – negas Aug 14 '22 at 02:37
1

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
gustavz
  • 2,964
  • 3
  • 25
  • 47