# Getting directory of current notebook within notebook

**URL:** <https://forum.access-hive.org.au/t/getting-directory-of-current-notebook-within-notebook/5825>\
**Category:** Technical\
**Tags:** python, jupyter, help, jupyterlab, community-help\
**Created:** [26 January 2026 23:36 UTC](https://forum.access-hive.org.au/t/getting-directory-of-current-notebook-within-notebook/5825 "2026-01-26T23:36:28Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![aekiss](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.access-hive.org.au/aekiss/32/46_2.png) [@aekiss](https://forum.access-hive.org.au/u/aekiss)\
**Post date:** [26 January 2026 23:36 UTC](https://forum.access-hive.org.au/t/getting-directory-of-current-notebook-within-notebook/5825/1 "2026-01-26T23:36:28Z")

</div>

Hi, is there a way to get the path to the currently running jupyter python notebook from within that notebook on ARE? Knowing the path to the current notebook would be super handy for saving outputs in the same folder as the notebook file.

From a bit of web searching it seems there’s no general solution, but lots of approaches that work in particular circumstances. I’ve tried a lot of them, but nothing has worked so far for JupyterLab on ARE.

---

<div class="post-metadata">

**Author:** ![paigem](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.access-hive.org.au/paigem/32/928_2.png) [@paigem](https://forum.access-hive.org.au/u/paigem)\
**Post date:** [27 January 2026 00:56 UTC](https://forum.access-hive.org.au/t/getting-directory-of-current-notebook-within-notebook/5825/2 "2026-01-27T00:56:45Z")

</div>

@aekiss I just asked around at ACCESS-NRI and the consensus is that this is very difficult to do and no one has found a general solution to this…

Perhaps someone else in the community has found a solution?

---

<div class="post-metadata">

**Author:** ![aekiss](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.access-hive.org.au/aekiss/32/46_2.png) [@aekiss](https://forum.access-hive.org.au/u/aekiss)\
**Post date:** [27 January 2026 02:19 UTC](https://forum.access-hive.org.au/t/getting-directory-of-current-notebook-within-notebook/5825/3 "2026-01-27T02:19:58Z")

</div>

OK ta. I don’t need a general solution, just one that works on ARE.

---

<div class="post-metadata">

**Author:** ![eliocamp](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.access-hive.org.au/eliocamp/32/4273_2.png) [@eliocamp](https://forum.access-hive.org.au/u/eliocamp)\
**Post date:** [27 January 2026 03:14 UTC](https://forum.access-hive.org.au/t/getting-directory-of-current-notebook-within-notebook/5825/4 "2026-01-27T03:14:46Z")

</div>

From what I read, it’s simply not possible to reliably get the path to a python notebook:

> <https://stackoverflow.com/questions/52119454/how-to-obtain-jupyter-notebooks-path>

What is your use case?

If you have a single notebook and you want to create output for, then my advise would be to write code using always relative paths to the root of the project you are working on and always run code with the project root as the working directory. This ensures that your code is portable; you can move your whole project somewhere else and everything will keep working.

On ARE, you can do this with the `–notebook-dir` argument. For example, if you add this:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/access1/original/2X/0/0d2373c6be02627f5b31f8d657f979e517d0c47a.png)

The your working directory will be `~/research/access-exp` and any code you run in that session will use that as the root.

If you have code that creates a bunch of output files and want the path to the script to be some sort of automatic “argument”, then you could work with regular python scripts and use

```python

import os
file_path = os.path.realpath( __file__ )

```

To get the path to the script and then run it from the terminal.

I hope that helps.

---

<div class="post-metadata">

**Author:** ![Scott](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.access-hive.org.au/scott/32/37_2.png) [@Scott](https://forum.access-hive.org.au/u/Scott)\
**Post date:** [27 January 2026 03:21 UTC](https://forum.access-hive.org.au/t/getting-directory-of-current-notebook-within-notebook/5825/5 "2026-01-27T03:21:09Z")

</div>

Try setting up a token for jupyter lab

```auto
echo "c.IdentityProvider.token = '$(uuidgen)'" >> ~/.jupyter/jupyter_lab_config.py

```

then

```auto
import ipynbname
ipynbname.path()

#> PosixPath('/home/562/saw562/home/tmp/Untitled41.ipynb')

```

Make sure the config file is only readable by you

```auto
chmod go-rwx ~/.jupyter

```

---

<div class="post-metadata">

**Author:** ![Scott](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.access-hive.org.au/scott/32/37_2.png) [@Scott](https://forum.access-hive.org.au/u/Scott)\
**Post date:** [27 January 2026 03:24 UTC](https://forum.access-hive.org.au/t/getting-directory-of-current-notebook-within-notebook/5825/6 "2026-01-27T03:24:37Z")

</div>

You’ll need to substitute `$HOME` with `$HOME/.jupyter_root` to get the true path

---

<div class="post-metadata">

**Author:** ![rui.yang](https://avatars.discourse-cdn.com/v4/letter/r/ce7236/32.png) [@rui.yang](https://forum.access-hive.org.au/u/rui.yang)\
**Post date:** [27 January 2026 11:48 UTC](https://forum.access-hive.org.au/t/getting-directory-of-current-notebook-within-notebook/5825/7 "2026-01-27T11:48:41Z")

</div>

NCI has developed a Python package called **nci-ipynb** to help identify the directory where your notebook is located when running it in an ARE JupyterLab session. For more information and usage instructions, see:

[https://opus.nci.org.au/spaces/DAE/pages/477823998/NCI-ipynb](https://opus.nci.org.au/spaces/DAE/pages/477823998/NCI-ipynb)

---

<div class="post-metadata">

**Author:** ![aekiss](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.access-hive.org.au/aekiss/32/46_2.png) [@aekiss](https://forum.access-hive.org.au/u/aekiss)\
**Post date:** [27 January 2026 23:12 UTC](https://forum.access-hive.org.au/t/getting-directory-of-current-notebook-within-notebook/5825/8 "2026-01-27T23:12:23Z")

</div>

Great, thanks all, I was wanting something I could put in the notebook so that anyone could clone it from a repo and have it save files to the cloned dir when run on ARE, and it looks like @rui.yang’s solution would work for that use case.

Would it be possible to include nci-ipynb in conda/analysis3?

---

<div class="post-metadata">

**Author:** ![paigem](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.access-hive.org.au/paigem/32/928_2.png) [@paigem](https://forum.access-hive.org.au/u/paigem)\
**Post date:** [28 January 2026 01:57 UTC](https://forum.access-hive.org.au/t/getting-directory-of-current-notebook-within-notebook/5825/9 "2026-01-28T01:57:44Z")

</div>

That’s a great idea to add nci-ipynb to conda/analysis3! I just started [an issue in the conda/analysis3 repo](https://github.com/ACCESS-NRI/ACCESS-Analysis-Conda/issues/359) to request the addition.

---

<div class="post-metadata">

**Author:** ![aekiss](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.access-hive.org.au/aekiss/32/46_2.png) [@aekiss](https://forum.access-hive.org.au/u/aekiss)\
**Post date:** [28 January 2026 02:57 UTC](https://forum.access-hive.org.au/t/getting-directory-of-current-notebook-within-notebook/5825/10 "2026-01-28T02:57:32Z")

</div>

Great, thanks @paigem 🙂

---

<div class="post-metadata">

**Author:** ![aekiss](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.access-hive.org.au/aekiss/32/46_2.png) [@aekiss](https://forum.access-hive.org.au/u/aekiss)\
**Post date:** [14 April 2026 04:31 UTC](https://forum.access-hive.org.au/t/getting-directory-of-current-notebook-within-notebook/5825/11 "2026-04-14T04:31:45Z")

</div>

[NCI-ipynb](https://opus.nci.org.au/spaces/DAE/pages/477823998/NCI-ipynb) is now available in [`conda/analysis3-26.03`](https://github.com/ACCESS-NRI/ACCESS-Analysis-Conda/pull/384), so if you’re using that kernel on ARE you can get the current notebook’s filename, directory path and full file path via

```python
import nci_ipynb
nci_ipynb.name()
nci_ipynb.dir()
nci_ipynb.path()

```

---

<div class="post-metadata">

**Author:** ![cbull](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.access-hive.org.au/cbull/32/2203_2.png) [@cbull](https://forum.access-hive.org.au/u/cbull)\
**Post date:** [21 July 2026 04:16 UTC](https://forum.access-hive.org.au/t/getting-directory-of-current-notebook-within-notebook/5825/12 "2026-07-21T04:16:34Z")

</div>

It’s been a bit flakey for me lately…

> <https://github.com/ACCESS-NRI/ACCESS-Analysis-Conda/issues/359#issuecomment-4998951381>
>
> \### Package Name
> 
> nci-ipynb
> 
> \### Preferred Version (Optional)
> 
> \_No response\_
> 
> \##…# Target Environment
> 
> analysis3-YY.MM (stable environment with proven compatibility)
> 
> \### Use Case and Community Value
> 
> This package allows users to identify the directory they are in from within a notebook running on NCI ARE. Please see \[this discussion on the Hive Forum\](https://forum.access-hive.org.au/t/getting-directory-of-current-notebook-within-notebook/5825) for more details.
> 
> I'm putting in this issue on behalf of @aekiss.
> 
> \### Known Dependencies
> 
> \_No response\_
> 
> \### Package Maintenance Status
> 
> \- \[\] The package is actively maintained on GitHub/GitLab
> \- \[\] The package has recent releases (within the last 2 years)
> \- \[\] The package is available on conda-forge or a similar reliable channel
> 
> \### Impact on Key SPEC0 Packages
> 
> Unknown - needs investigation
> 
> \### Alternatives Considered
> 
> \_No response\_
> 
> \### Additional Information
> 
> \_No response\_
