# Jupyter notebook working directory not set correctly

**URL:** <https://discourse.openondemand.org/t/jupyter-notebook-working-directory-not-set-correctly/4629>\
**Category:** Get Help\
**Created:** [November 12, 2025, 3:41pm UTC](https://discourse.openondemand.org/t/jupyter-notebook-working-directory-not-set-correctly/4629 "2025-11-12T15:41:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sebastian-burlacu](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/sebastian-burlacu/32/2440_2.png) [@sebastian-burlacu](https://discourse.openondemand.org/u/sebastian-burlacu)\
**Post date:** [November 12, 2025, 3:41pm UTC](https://discourse.openondemand.org/t/jupyter-notebook-working-directory-not-set-correctly/4629/1 "2025-11-12T15:41:20Z")

</div>

This seems to work for some users, but not others. The before.sh scripts are the exact same - they are supposed to write to config.py - but the resulting files are different. It would seem that HOME is somehow not defined for one user, but it is hard to tell why. They can run regular batch jobs just fine, and those jobs can see $HOME.

Both output files (with some redaction):

> root@ood04:/h/userone/ondemand/data/sys/dashboard/batch\_connect/sys/jupyter-22/form/output/0b907c78-9c6d-4d92-bd68-df0f22d68e03# cat config.py  
> c.JupyterApp.config\_file\_name = ‘ondemand\_config’  
> c.NotebookApp.ip = ‘_’  
> c.NotebookApp.port = 33039  
> c.NotebookApp.port\_retries = 0  
> c.NotebookApp.password = u’sha1:blah:blah’  
> c.NotebookApp.base\_url = ‘/node/gpu002/33039/’  
> c.NotebookApp.open\_browser = False  
> c.NotebookApp.allow\_origin = '_’  
> c.NotebookApp.notebook\_dir = ‘/h/userone’  
> c.NotebookApp.disable\_check\_xsrf = True  
> c.NotebookApp.nbserver\_extensions = {“jupyterlmod”: True}  
> root@ood04:/h/userone/ondemand/data/sys/dashboard/batch\_connect/sys/jupyter-22/form/output/0b907c78-9c6d-4d92-bd68-df0f22d68e03# cd -  
> /h/usertwo/ondemand/data/sys/dashboard/batch\_connect/sys/jupyter-22/form/output/edeaf236-2093-4539-a0f0-59a6f20f2070  
> root@ood04:/h/usertwo/ondemand/data/sys/dashboard/batch\_connect/sys/jupyter-22/form/output/edeaf236-2093-4539-a0f0-59a6f20f2070# cat config.py  
> c.JupyterApp.config\_file\_name = ‘ondemand\_config’  
> c.NotebookApp.ip = ‘_’  
> c.NotebookApp.port = 11341  
> c.NotebookApp.port\_retries = 0  
> c.NotebookApp.password = u’sha1:blah:blah’  
> c.NotebookApp.base\_url = ‘/node/gpu002/11341/’  
> c.NotebookApp.open\_browser = False  
> c.NotebookApp.allow\_origin = '_’  
> c.NotebookApp.notebook\_dir = ‘’  
> c.NotebookApp.disable\_check\_xsrf = True  
> c.NotebookApp.nbserver\_extensions = {“jupyterlmod”: True}

---

<div class="post-metadata">

**Author:** ![hansen-m](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/hansen-m/32/2200_2.png) [@hansen-m](https://discourse.openondemand.org/u/hansen-m)\
**Post date:** [November 12, 2025, 4:38pm UTC](https://discourse.openondemand.org/t/jupyter-notebook-working-directory-not-set-correctly/4629/2 "2025-11-12T16:38:02Z")

</div>

Have you tested with clean home directories? Any differences in .bashrc or something like that? Any additional modules being loaded that differ?

Not sure if this helps, but I don’t set the working dir in before.sh and instead I set `--notebook-dir` it in the script.sh.erb

```auto
# Start Jupyter Notebook
<%= context.jupyter_exec %> --no-browser --ip=${ip} --port=${port} \
  --NotebookApp.base_url=/node/${host}/${port} \
  --NotebookApp.password="${JUPYTER_PASSWORD}" \
  --NotebookApp.disable_check_xsrf=True \
  --notebook-dir=${HOME} \
  --NotebookApp.allow_origin='*' \
  --NotebookNotary.db_file=':memory:'

```

---

<div class="post-metadata">

**Author:** ![jeff.ohrstrom](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/jeff.ohrstrom/32/136_2.png) [@jeff.ohrstrom](https://discourse.openondemand.org/u/jeff.ohrstrom)\
**Post date:** [November 12, 2025, 7:14pm UTC](https://discourse.openondemand.org/t/jupyter-notebook-working-directory-not-set-correctly/4629/3 "2025-11-12T19:14:13Z")

</div>

> [@sebastian-burlacu](#):
>
> This seems to work for some users, but not others.

There may also be an environment variable or python scripts in their HOME that do something different for those specific users.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex015/uploads/osc/original/2X/b/bae70bd0ed39a3ae769c2108155f4cb3e9da8385.png) [@system](https://discourse.openondemand.org/u/system)\
**Post date:** [May 11, 2026, 7:14pm UTC](https://discourse.openondemand.org/t/jupyter-notebook-working-directory-not-set-correctly/4629/4 "2026-05-11T19:14:17Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
