NickS1
NickS1

Reputation: 594

How to set default folder in JupyterLab file browser?

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!

Upvotes: 4

Views: 9049

Answers (4)

Martin
Martin

Reputation: 1001

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'

Upvotes: 1

BKumarAtanu
BKumarAtanu

Reputation: 9

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. **

Upvotes: 1

krassowski
krassowski

Reputation: 15439

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.

Upvotes: 4

BKumarAtanu
BKumarAtanu

Reputation: 9

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.

Upvotes: 0

Related Questions