Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set notebook working directory on server level #7525

Open
ylieder opened this issue Nov 28, 2024 · 2 comments
Open

Set notebook working directory on server level #7525

ylieder opened this issue Nov 28, 2024 · 2 comments

Comments

@ylieder
Copy link

ylieder commented Nov 28, 2024

Problem

Usually in my Python projects I follow the following project structure:

- project root dir
   - app (Python module/package)
   - notebooks 
      - subdir
        - notebook1.ipynb
      - notbook2.ipynb 
   - data

So my notebooks are in several hierarchy levels in a notebooks folder.
When I now start a Jupyter notebook server from the root folder, I would like to be able to specify that the working directory of the notebook is the root folder, such that I have direct access to e.g. data and app, independently of the running notebook and its location in the file hierarchy.

There is the option jupyter notebook --root-dir, but this does not change the actual working directories of the notebooks, just the default entry path of the server app.

Proposed Solution

Adding command line arguments for jupyter notebook to set the working directory for each notebook, wherever it is located. E.g.:

jupyter notebook --exec_dir / --working_dir .
# or
jupyter notebook --exec_dir / --working_dir <absolute path>

Additional context

VSCode Jupyter extension offers an option archiving exactly the behaviour:

{
  "jupyter.notebookFileRoot": "${workspaceFolder}"
}

The feature is searched for at several Stackoverflow threads, e.g.:
https://stackoverflow.com/questions/67287424/how-to-change-jupyter-notebooks-working-directory-configuration
https://stackoverflow.com/questions/15680463/change-ipython-jupyter-notebook-working-directory#comment103251523_15682400

@ylieder ylieder added enhancement status:Needs Triage Applied to issues that need triage labels Nov 28, 2024
@krassowski
Copy link
Member

Also requested in jupyterlab/jupyterlab#11619 (see some workarounds in the comments).

Really, what most users are after is modifying PYTHONPATH variable for given project. One can set it in kernelspec .json file using an environment variable but this is just not convenient.

More generally, the PYTHONPATH comes from the (working) directory in which kernels are starting up. I think that this option should be named --kernel-startup-dir or similar. Thoughts?

@ylieder
Copy link
Author

ylieder commented Nov 28, 2024

Oh, didn't see that there is already an issue for it and also didn't found the StackOverflow thread. Thank you for reference!
I use similar workarounds in my projects, but IMHO much less convenient than the suggested feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants