dzieciou
dzieciou

Reputation: 4514

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?

Upvotes: 20

Views: 29993

Answers (3)

max
max

Reputation: 191

This has been answerd in this post: don't use ! before pip command because it is executed as in command line, instead use the % sign to execute inside the virtual evironment of the current ipython kernel.

Upvotes: 10

negas
negas

Reputation: 919

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 

Upvotes: 16

gustavz
gustavz

Reputation: 3160

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

Upvotes: 1

Related Questions