Import local function from a module housed in another directory with relative imports in Jupyter Notebook using Python 3

后端 未结 7 1192
灰色年华
灰色年华 2020-12-04 05:23

I have a directory structure similar to the following

meta_project
    project1
        __init__.py
        lib
            module.py
            __init__.py         


        
7条回答
  •  有刺的猬
    2020-12-04 06:05

    I have just found this pretty solution:

    import sys; sys.path.insert(0, '..') # add parent folder path where lib folder is
    import lib.store_load # store_load is a file on my library folder
    

    You just want some functions of that file

    from lib.store_load import your_function_name
    

    If python version >= 3.3 you do not need init.py file in the folder

提交回复
热议问题