jupyter notebook导入上级目录的文件

在jupyter中,使用:os.path.realpath(".")可以得到当前文件的路径

import sys
import os
os.chdir(os.path.dirname(os.path.realpath(".")))
sys.path.insert(0, '..') # 添加上级路径

后面的代码不用变,后续再导入上级路径的时候就不会报找不到路径/模块了

你可能感兴趣的:(python,jupyter,python)