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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With