jorgehumberto jorgehumberto - 1 year ago 161
Python Question

Jupyter notebook wrong path

I need to test a few functions from a code I am building which I import into a jupyter notebook.

issue is, simTools_path is different in the functions and the jupyter notebook. More, when I call these functions from my main python script, it works fine.



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

def testPath():
print 'testPath', simTools_path

jupyter notebook

import os,sys
# paths
simTools_path = os.path.abspath('../')
os.environ["SIMTOOLS_PATH"] = "simTools_path"
os.environ["PYTHONPATH"] = "simTools_path"

from objects.classes import testPath

print simTools_path


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) I use this path variable in different functions inside different modules to load file data relatively to the simTools_path path.

2) my jupyter notebook is located in /home/jhumberto/WORK/Projects/code/simulations_2016-07-14/simTools/jupyterNotebooks

Any ideas?

Answer Source

You have confused the variable simTools_path and the literal string "simTools_path". To correct the problem, simply change the line as follows:

os.environ["SIMTOOLS_PATH"] = simTools_path