jupyter notebook Method for specifying the startup directory

  • 2021-09-12 01:42:44
  • OfStack

Source of problem

After jupyter notebook is started on the command line, the default root directory is the current directory of the command line, which is less convenient.
Here are three ways to specify the startup directory, which are suitable for different scenarios.

Solution

Method 1: Switch to the specified directory on the command line, and then run jupyter notebook

This method is a more conventional method and the simplest solution.
Each time you run jupyter notebook, switch directories on the command line using the cd command, and then run jupyter notebook.

Method 2: Modify the default open location to be suitable for running jupyter notebook in a fixed directory every time

This method is suitable for running jupyter notebook in a fixed directory every time.

First, enter the command on the command line: jupyter notebook--generate-config to generate the configuration file, and when the command is executed, the path to the configuration file is displayed.


 C:\Users\Administrator>jupyter notebook --generate-config
 Writing default config to: C:\Users\Administrator\.jupyter\jupyter_notebook_config.py

Open the configuration file jupyter_notebook_config. py, locate the c. NotebookApp.notebook_dir configuration entry, remove the comments, and add the specified directory.


## The directory to use for notebooks and kernels.
#c.NotebookApp.notebook_dir = ''

c.NotebookApp.notebook_dir = 'r'e:/testpath''

From the command line, just run jupyter notebook, so that whatever the current directory in the command is, jupyter notebook opens the specified e:\ testpath.

Method 3: jupyter notebook-notebook-dir= 'd:/download'

In fact, the jupyter notebook command already provides parameters to run in the specified directory-notebook-dir. This method is more flexible, without switching directories. Of course, you don't have to modify the configuration file.


--notebook-dir=<Unicode> (NotebookApp.notebook_dir)
  Default: ''
  The directory to use for notebooks and kernels.

Summarize

Among these three methods, the first method of switching directories is more conventional, the second method needs to modify the configuration file, which is suitable for opening jupyter notebook in a fixed directory every time. If the directory needs to be changed, it is quite troublesome to modify the configuration file every time. The third method is flexible and suitable for temporarily specifying the startup directory.

Of course, the first method and the third method can achieve the effect of the second method by writing simple batch processing, which is also a common method for many people to avoid the trouble of entering commands every time you open the command line. This batch writing is very simple, no longer demo, create a text file, write a related command per line, save as. bat file.


Related articles: