# How to reference root directory?

**URL:** <https://discourse.jupyter.org/t/how-to-reference-root-directory/11110>\
**Category:** JupyterLab\
**Created:** [October 5, 2021, 9:32am UTC](https://discourse.jupyter.org/t/how-to-reference-root-directory/11110 "2021-10-05T09:32:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![J\_RB](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/j_rb/32/5397_2.png) [@J\_RB](https://discourse.jupyter.org/u/J_RB)\
**Post date:** [October 5, 2021, 9:32am UTC](https://discourse.jupyter.org/t/how-to-reference-root-directory/11110/1 "2021-10-05T09:32:49Z")

</div>

I typically have several Juypterlab launchers each with different starting directories (local, networkshare 1,2,3…) as I store RAW data and associated post-processing in relevant directory structures.

I typically keep a processingLib in this root directory and it usually contains specific parsing functions, as a group of tests may have a different acquisition setup (scope channels, power analyser…), while larger re-use calls are added as a git submodule.

```auto
> <root>
ProcessingLib
└─HelperLib
└─TestSuite_1
    └─ some_file.ipynb
└─TestSuite_2
    └─ another_file.ipynb
    └─ another_file_PRESENTATION.ipynb
└─TestSuite_3
      └─ looksee_file.ipynb
      └─TestSuite_3_1
               └─ additional_file.ipynb

```

For the above example structure I would group suites of tests in their own directories and have one or many notebooks to process and document the postprocessing. At the start of each notebook, after a heading markdown I would typically add a “houskeeping imports” codeblock

```auto
#housekeeping imports
import IPython
import numpy as np
import pandas as pd
import sympy as sym
import seaborn as sns
import scipy.signal as signal
from scipy.optimize import curve_fit
from IPython.display import display,HTML,Markdown 
from dataclasses import dataclass

import sys
sys.path.insert(0,'..')
from ProcessingLib import some_module

```

This obviously works for TestSuite\_1,TestSuite\_2 and TestSuite\_3 but would fail for TestSuite\_3\_1 directory and I would need to change the sys.path.insert to: **sys.path.insert(0,’… /…’)** ( note discourse has changed two dots to three in main body text…)

Is there some ENV that juypyterlab sets which is the absolute path of that I can instead use for some import to provide a consistent housekeeping import block and minimize worrying about the depth of the directory structure being used

---

<div class="post-metadata">

**Author:** ![krassowski](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/krassowski/32/1685_2.png) [@krassowski](https://discourse.jupyter.org/u/krassowski)\
**Post date:** [October 9, 2021, 11:31am UTC](https://discourse.jupyter.org/t/how-to-reference-root-directory/11110/2 "2021-10-09T11:31:17Z")

</div>

I described my setup in [ipython - How to set the default working directory of all Jupyter Notebooks as the project's parent folder - Stack Overflow](https://stackoverflow.com/a/69399208/6646912). Briefly I have a file called `make_paths_absolute.py` in the root which contains the following code:

```python
from os import chdir
from pathlib import Path

def make_paths_relative_to_root():
    """Always use the same, absolute (relative to root) paths

    which makes moving the notebooks around easier.
    """
    top_level = Path( __file__ ).parent

    chdir(top_level)

make_paths_relative_to_root()

```

In the “houskeeping imports” codeblock I always start from:

```python
import make_paths_absolute

```

And that never let me down 😉

PS. the above is a simplification, I have `make_paths_absolute` in `helpers/` and I have another `.parent` to account for that, and I also try to avoid having more than two lines in the houskeeping block by having a dedicated “housekeeping notebook” executed by `%run`, but the above gives you the gist.
