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:
- Use cd command to move to the desired directory
- Use option –notebook-dir
- 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
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"
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/’.
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.
Thanks for sharing!
The clear instruction for Mac config is very useful
What are the change ops for Microsoft.Or is notebook on Juypter ? Just an Error.