Custom modules importing in terminal but not notebook

I’m running a notebook in JupyterLab and want to import a module contained in the same folder as the notebook. The file structure:

|___ notebook.ipynb

It works in terminal: I can import some_module and use its functions from both python3 and ipython.

Inside the .ipynb I can import some_module, meaning that the module is on the sys.path and gets found. But if I call e.g. function some_module.f() I get module 'some_module' has no attribute 'f'. I can’t access any function from some_module at all.

Check some key values, such as:

  • sys.prefix
  • sys.executable
  • sys.path

Any deviation in those (caused by startup/shell PATH, PYTHONPATH, etc) might be the culprit.

You also certainly can’t trust __file__, PYTHONPATH and other tricks, as there are rather a lot of different processes, operating in different modes, depending on how they were launched.

I don’t know what fixed it, but after doing other things for a few days my module now loads properly into Jupyter Lab. I’ll use your advice if the problem happens again, so thank you for your help :slight_smile: