2

I created a virtual environment, installed pandas and some other libraries, changed the ipython kernel and then opened jupyter inside my virtual environment. Pandas and other libraries worked fine.

Then i installed fastai in my virtualenv, but it shows ModuleNotFoundError in Jupyter only. It works fine in terminal, when i run !pip freeze inside Jupyter it lists 'fastai', when i try to install it in jupyter with '!pip install fastai' it shows 'Requirement already satisfied' but importing it still gives me 'ModuleNotFoundError'. Check this image for example

All answers on SO to this question are for people who haven't changed their jupyter kernel to their environment or who have had other issues, but i couldn't find my issue.

Mazhar Ali
  • 63
  • 9
  • [This post](https://stackoverflow.com/questions/54718912/modulenotfounderror-no-module-named-scikit) seems reminiscent and has some useful comments. I'll point out that one of the links is old and now there is `%pip install ` for use in Jupyter. – Wayne Feb 15 '20 at 20:30
  • Please do not share information as images unless absolutely necessary. See: https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors. – AMC Feb 16 '20 at 03:21
  • 1
    I did the pip install. It says the module is already installed. That is why !pip freeze is showing it. @AMC the image was to show people that it IS installed in jupyter and IS showing there. – Mazhar Ali Feb 17 '20 at 15:42

1 Answers1

1

You have to add the virtualenv to the kernel. Nice discussion is here (Execute Python script within Jupyter notebook using a specific virtualenv).

Assuming virtualenv is working fine (jupyter-notebook and fastai are working), these are the additional steps, I might have tried. In the second line (below) change the "--name=NameOfVirtualEnv" appropriately with the name of your virtualenv.

pip install --user ipykernel
python -m ipykernel install --user --name=NameOfVirtualEnv

After that once you start the Jupyter notebook, you will see the "New" dropdown to the right side .. there you will have your virtual environment with the fastai.

Please let me know the outcome. Curious if it worked for you.

Amit
  • 2,018
  • 1
  • 8
  • 12
  • 1
    As i said, i already did these steps. I am inside the virtual env inside jupyter, that is why fastai and other libraries installed in my virtual environment are showing with pip freeze. – Mazhar Ali Feb 15 '20 at 19:05