Sys.Path Different in Jupyter and Python - How to Import Own Modules in Jupyter

How to make Jupyter notebook use PYTHONPATH in system variables without hacking sys.path directly?

Jupyter uses its own JUPYTER_PATH environment variable.

Cannot import a module which is in jupyter path

I cannot reproduce your issue without additional details but I would like to provide you with some work-around that should let you load your modules in /Users/me/myModules without changing the directory in Jupyter:

import os
from importlib.util import spec_from_file_location, module_from_spec

path = 'full/path/to/Users/me/myModules'

for fn in os.listdir(path):
fp = os.path.join(path, fn)
spec = spec_from_file_location(fn, fp)
mod = module_from_spec(spec)
spec.loader.exec_module(mod)

After running this piece of code, your modules will be already imported and free to use.



Related Topics



Leave a reply



Submit