I was wondering if there is a way to set a default folder every time I open JupyterLab. Is there any command I can run through Anaconda PowerShell Prompt? Or a JSON property I can modify in settings tab? Thanks in advance!
-
2https://stackoverflow.com/a/40514875/6646912 could help you, but use `jupyter server --generate-config` instead, and `c.ServerApp.root_dir` – krassowski Sep 03 '21 at 09:24
4 Answers
If you want to open specific file in directory a
, say a/notebook.ipynb
but then navigate the file browser to directory b
, relative to the root directory, you can use file-browser-path
query in the navigation URL (documented here):
http(s)://<server:port>/<lab-location>/lab/tree/a/notebook.ipynb?file-browser-path=/b
You can use this method from command line thanks to LabApp.default_url
traitlet:
jupyter-lab --LabApp.default_url='/lab/tree/a/notebook.ipynb?file-browser-path=/b'
You can skip the opening specific file part:
jupyter-lab --LabApp.default_url='/lab?file-browser-path=/b'
If you want to change the root directory, please see this answer which explains how to do so with ServerApp.root_dir
traitlet (in older versions of Notebook<7.0 and JupyterLab<3.0 used to be named NotebookApp.notebook_dir
). Again, you can use it from command line, and even specify an absolute path:
jupyter-lab --ServerApp.root_dir='/home/user/project/'
# or on Windows say:
# jupyter-lab --ServerApp.root_dir='C/users/user/project/'
You can combine the two approaches, e.g.:
jupyter-lab --ServerApp.root_dir='/home/user/project/' --LabApp.default_url='/lab?file-browser-path=/project_subdirectory'
If you want to persist the changes (for either default URL or root dir), see the previously linked answer which details how to persist configuration.

- 13,598
- 4
- 60
- 92
According to the jupyter.org: I configured like this.
Terminal command active your envirnment by conda activate Your_env_name
and then jupyter lab --generate-config
. jupyter_lab_config.py should be created in dir /home/$USER/.jupyter directory.
Find
# c.LabApp.app_settings_dir = ''
and uncomment.
Then give your directory like this.
c.LabApp.app_settings_dir = '/home/$USER/Documents/Jupyter_Notebook'
Similar for jupyter notebook. jupyter notebook --generate-config
and then nu-comment and edit like c.NotebookApp.notebook_dir = '/home/UserName/Documents/Jupyter_Notebook'
**NB: /home/$USER/Documents/Jupyter_Notebook
is my changed default dir. Change it according to your need. **

- 11
- 4
-
I don't believe that `app_settings_dir` is needed. Why did you include it? – krassowski Feb 15 '22 at 14:33
-
`c.LabApp.app_settings_dir` is needed for Jupyter Lab and for Jypyter Notebook `c.NotebookApp.notebook_dir` . – AtanuKB1794 Feb 16 '22 at 18:47
The command
jupyter notebook --generate-config
will create a config file. The path to this file is displayed in your terminal or PowerShell.
Set the desired folder path as the string c.ServerApp.root_dir
in this file and make sure you uncomment the line after you set the string.
Windows users will have to use double backslash in paths, e.g.:
c.ServerApp.root_dir = 'C:\\YOUR\\PATH'

- 659
- 7
- 14
Follow the answer . Just edit the alias alias my_jupn='source /home/$USER/anaconda3/bin/activate && conda activate MyPy38 && jupyter-notebook --notebook-dir=/home/$USER/Documents/Jupyter_Notebook'
and for JupyterLab alias my_jupl='source /home/$USER/anaconda3/bin/activate && conda activate MyPy38 && jupyter-lab --notebook-dir=/home/$USER/Documents/Jupyter_Notebook'
N.B. Here MyPy38 is your active environment name. and if any error occurs then change $USER
to your UserName
. Lastly, /home/$USER/Documents/Jupyter_Notebook
will be change according to your choice.

- 13,598
- 4
- 60
- 92

- 11
- 4