IPython PATH equivalent?

Let's say I have a python script test.py

in some pathpath_A

And let's say I have an IPython wrapper open in the path path_B


I would like to be able to:

run test.py


from path_B

(where the shell is open).

Is this possible in IPython? Is there something like a variable PATH

in IPython?


source to share

1 answer

Not how you describe it. The usual way is to os.chdir(path_A)

first ipython or just run path_A/test.py

as Thomas said in the comments.

Adding the PYTHONPATH environment variable as suggested in another answer here won't work for run

, because this is only used to find modules import


An alternative is to place path_A

in sys.path

(you can do this with the PYTHONPATH environment variable or preferably in the ipython config file that is started at startup). Then you can:

import test


This method will require you to refactor your code in test.py

so that it works at call time, not at import time.



All Articles