0

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?

2
  • 1
    Was the line os.environ["SIMTOOLS_PATH"] = "simTools_path" supposed to read os.environ["SIMTOOLS_PATH"] = simTools_path (no quote marks)? One points to the parent directory, the other to a folder called simTools_path within the current directory. Commented Aug 1, 2016 at 23:30
  • @mdurant silly me, that was it! Thanks! can you please write an answer so I can accept it? Commented Aug 2, 2016 at 20:45

1 Answer 1

1
+50

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 
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, that fixed it :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.