Importing custom module into jupyter notebook

后端 未结 7 1980
眼角桃花
眼角桃花 2021-02-05 05:55

Yes, I know this is a recurrent question but I still couldn\'t find a convincing answer. I even read at https://chrisyeh96.github.io/2017/08/08/definitive-guide-python-imports.h

7条回答
  •  北海茫月
    2021-02-05 06:08

    One can tell python where to look for modules via sys.path. I have a project structure like this:

    project/
        │
        ├── src/
        │    └── my_module/
        │        ├── __init__.py       
        │        └── helpers.py
        ├── notebooks/
        │   └── a_notebook.ipynb
        ...
    

    I was able to load the module like so:

    import sys
    sys.path.append('../src/')
    
    from my_module import helpers
    

    One should be able load the module from wherever they have it.

提交回复
热议问题