Reputation: 1097
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.
MWE
simTools_path/objects/classes.py
simTools_path = os.path.abspath(os.getenv('SIMTOOLS_PATH'))
sys.path.append(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"
sys.path.append(simTools_path)
from objects.classes import testPath
print simTools_path
testPath()
results:
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
Notes:
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?
Upvotes: 0
Views: 1540
Reputation: 28684
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
Upvotes: 1