Jupyter笔记本错误路径

2024-06-26 13:31:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要从我正在构建的代码中测试几个函数,并将其导入jupyter笔记本。在

问题是,simTools_path在函数和jupyter笔记本中是不同的。而且,当我从python主脚本调用这些函数时,它工作得很好。在

MWE

simTools_路径/对象/类.py

simTools_path = os.path.abspath(os.getenv('SIMTOOLS_PATH'))
sys.path.append(simTools_path)

def testPath():
    print 'testPath', simTools_path

jupyter笔记本

^{pr2}$

结果:

simTools_path= /home/jhumberto/WORK/Projects/code/simulations_2016-07-14/simTools
testPath= /home/jhumberto/WORK/Projects/code/simulations_2016-07-14/simTools/jupyterNotebooks/simTools_path

注释:

1)我在不同模块内的不同函数中使用此路径变量来加载相对于simTools_path路径的文件数据。在

2)我的jupyter笔记本位于/home/jhumberto/WORK/Projects/code/simulations_2016-07-14/simTools/jupyterNotebooks

有什么想法吗?在


Tags: path函数路径homeoscode笔记本jupyter