Change Jupyter Notebook startup folder on Windows and Mac OS


Once we have installed the Jupyter notebook, we can start it by executing “jupyter notebook” command in the command prompt on a Windows machine or in the terminal on a Mac machine. Jupyter notebook is a very useful web-based application which can be used to write programs in many programming languages like Python, R, Scala, Julia, and etc. The notebooks created in jupyter can be shared easily with other users over email, Git, and DropBox. We can use jupyter notebooks to write code in an interactive mode which can be very handy to re-run individual snippets. It is nicely integrated with Big Data ecosystem and with cloud platforms also.

When we start the jupyter notebook server, it shows the notebooks from the current working directory from which the notebook server is started. That is why the default working directory of a Jupyter notebook server is “C:\Users\UserName” on a Windows machine and “/Users/UserName” on a Mac machine.

We have many ways to show the notebooks from a different directory than the default location. For example:

  1. Use cd command to move to the desired directory
  2. Use option –notebook-dir
  3. Use a config file

Let’s discuss these methods in detail now.

Method 1 – Use cd command to move to the desired directory

In order to show the notebooks from a different directory, first, we need to navigate to the desired directory in the command prompt or in the terminal window using “cd/MySourceCode/MyFolder” and then we can start the notebook server. 

cd c:\JupyterFiles
jupyter notebook
Change notebook directory using cd command

Change notebook directory using cd command

However, switching to the source code directory each time we need to start the jupyter server becomes annoying.

Method 2 – Use option –notebook-dir

We can also pass the desired directory path as a parameter value using option –notebook-dir while starting the jupyter notebook server.

jupyter notebook --notebook-dir="c:\JupyterFiles"
Change notebook directory using notebook-dir option

Change notebook directory using notebook-dir option

Method 3 – Use a config file

We can use a config file to set the working directory to the desired path so that the notebook server will always open up from that given directory. In this approach, we don’t need to change or pass the desired directory path each time we need to start the notebook server. This approach is better than other methods especially if we need to start the jupyter server from our source directory again and again.

1. In order to use the config file, we need to generate it using below command in Windows and Mac:

jupyter notebook --generate-config

This above command will generate a config file at “C:\Users\UserName\.jupyter\jupyter_notebook_config.py” on Windows machine and at “/Users/UserName/.jupyter/jupyter_notebook_config.py” on a Mac machine. If “.jupyter” folder is not visible at your Mac machine, go to /Users/UserName/ and press Command + Shift + . (dot) to show hidden files.

2. Now, open the config file “jupyter_notebook_config.py” in a text editor and find the text #c.NotebookApp.notebook_dir = ”

3. Uncomment this line by removing the # from the beginning of the line.

4. Replace the default blank value (”) with the desired source code directory path. In our case, this line will be c.NotebookApp.notebook_dir = ‘C:\\JupyterFiles\\’. On a Mac machine, this should look like c.NotebookApp.notebook_dir = ‘/Users/UserName/JupyterFiles/’.

Change notebook directory using config file

Change notebook directory using config file

5. Save this file and close the editor.

6. Start the jupyter notebook server using jupyter notebook command from command prompt/terminal. Now, the notebook server should show the notebooks from the given source code directory rather than the default user directory.

Thanks for the reading. Please share your inputs in the comment section.

Rate This
[Total: 0    Average: 0/5]

Gopal Krishna Ranjan

About Gopal Krishna Ranjan

Gopal is a passionate Data Engineer and Data Analyst. He has implemented many end to end solutions using Big Data, Machine Learning, OLAP, OLTP, and cloud technologies. He loves to share his experience at https://www.sqlrelease.com/. Connect with Gopal on LinkedIn at https://www.linkedin.com/in/ergkranjan/.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.