These are chat archives for ipython/ipython

1st
Feb 2018
Matěj Šmíd
@smidm
Feb 01 2018 09:12
Hi, anybody knows how to find the directory where jupyter notebook was started? %pwd is changed to the notebook directory, but I need to work back in the root of the project.
fterbo
@fterbo
Feb 01 2018 09:13
you can find the kernel directory using sys.exec_prefix
unclear that helps
not necessarily where it launched from
Matěj Šmíd
@smidm
Feb 01 2018 09:15
@fterbo no, that's something else
fterbo
@fterbo
Feb 01 2018 09:16
you can browse the process tree if you have privileges
psutil can do it in a reasonably cross-platform way
Matěj Šmíd
@smidm
Feb 01 2018 09:37
@fterbo thanks for the hint, this returns jupyter working directory:
import os
import psutil
psutil.Process(os.getpid()).parent().cwd()
fterbo
@fterbo
Feb 01 2018 09:40
excellent! :-)