0

I'm not able to find a package from my notebook when I have installed it via pip / conda in my terminal.

For example, I did pip install trading-calendars and conda install trading-calendars in terminal but from trading_calendars import get_calendar in Jupyter notebook throws a ModuleNotFoundError with the message No module named 'trading_calendars'.

Is it possible that Jupyter takes time to refresh? If this keeps happening despite restarting Jupyter notebook, what should I do?

Duplicates:

  1. How to list imported modules?
  2. Package for listing version of packages used in a Jupyter notebook

Possible solution:

  1. sys.path different in Jupyter and Python - how to import own modules in Jupyter?
Surya Narayanan
  • 418
  • 6
  • 9

1 Answers1

2

This can be pretty confusing with Jupyter. It's very important to realize that your Jupyter client can connect to different "kernels" which equates to various python environments you might have installed. That is, you can start the Jupyter server with one python environment, and be executing your notebook's cells from another.

You need to make sure that you have the libraries installed to the environment that your kernel is using.

You will need to generate a kernelspec for your environment if you haven't already.

You can create a kernelspec using ipykernel. Here's an example of me doing it with conda.

$ conda activate test
$ conda install ipykernel
$ python -m ipykernel install --user --name test \
--display-name "Python (test)"

You can view your kernelspecs with this command

 {~/path/to/project} (master *$)$  jupyter kernelspec list
Available kernels:
  django_extensions    /Users/nicholasbrady/Library/Jupyter/kernels/django_extensions
  python3              /Users/nicholasbrady/anaconda3/share/jupyter/kernels/python3
  python2              /usr/local/share/jupyter/kernels/python2
Nick Brady
  • 6,084
  • 1
  • 46
  • 71
  • I just deleted Miniconda and Conda keeps looking in the miniconda bin for stuff. I am unable to get it to look elsewhere, even with the path command. So when I run conda activate test, I get /Users/Surya/miniconda3/bin/conda: No such file or directory. What should I do? – Surya Narayanan Sep 10 '19 at 22:27
  • 1
    well, sounds like you need to have conda installed to use it.. reinstall it? That is a typical place to put it. – Nick Brady Sep 11 '19 at 09:24
  • Good idea - I had to delete conda – Surya Narayanan Sep 24 '19 at 02:10
  • 1
    lol... I just had this same problem that I already liked and tried to like it again. Note to self... add ipykernel to each conda env according the instructions in this post. – CodeSamurai-like May 29 '22 at 23:42