3

Say I have a python script test.py in some path path_A

And say I have an IPython shell open in a path path_B.

I would like to be able to do:

run test.py 

from path_B (where the shell is open).

Is that possible in IPython? Is there anything like a PATH variable in IPython?

1
  • You can cd path_A within IPython. Or specify run path_A/test.py. I can't think of another option off the top of my head. Commented Mar 7, 2012 at 22:18

1 Answer 1

3

Not how you describe. The usual way is to os.chdir(path_A) within ipython first, or just run path_A/test.py as Thomas said in the comments.

Adding the PYTHONPATH environment variable, as suggested in another answer here, will not work for run because this is only used for searching for import modules.

An alternative, is to put path_A into sys.path (you can do so using PYTHONPATH environment variable, or preferably, in the ipython config file which runs at startup). Then you would be able to do:

import test test.main() 

This method would necessitate you to restructure your code in test.py, so that it ran at call time rather than at import time.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.