ModuleNotFoundError: spec not found for the module

Viewed 1175

I am using Jupyter Notebook and trying to use some classes from a enums.py file. If I add new classes to that file, then it seems that I have to always restart the kernel in order to use them in other `.ipynb' files, which is not the best solution.

After searching more, I've found a better solution here How to reload a module's function in Python?, but I'm getting the following error and I'm not sure how to solve that:

ModuleNotFoundError: spec not found for the module 'enums'

This is my code from notebook.ipynb:

from importlib import reload
reload(enums)
from enums import FieldTypes, MyEnum

And this is the folder structure:

  Jupyter_Notebooks
  |--helpers
  |  |-- __init__.py
  |  |-- enums.py
  |  |-- notebook.ipynb
1 Answers

From the documentation (help(reload)): "The module must have been successfully imported before."

You must import enums for reload(enums) to work. See here for details on from-imports.

Related