Change Jupyter Notebook startup folder

Change Jupyter Notebook startup folder

?Tips and Tricks in Python

Image for postPhoto by Dave Gandy under the Public Domain Dedication License

TL;NR:

This is the method I used most:

cd into the directory or a parent directory (with the intended directory you will work nested in it).Then just run the command jupyter notebook

There are many ways you can change Jupiter notebook startup folder. Here I put a collection of them below for your reference.

1. Change Jupyter Notebook startup folder (Windows)

  • Copy the Jupyter Notebook launcher from the menu to the desktop.
  • Right click on the new launcher and change the Target field, change %USERPROFILE% to the full path of the folder which will contain all the notebooks.
  • Double-click on the Jupyter Notebook desktop launcher (icon shows [IPy]) to start theJupyter Notebook App. The notebook interface will appear in a new browser window or tab. A secondary terminal window (used only for error logging and for shut down) will be also opened.

2. Change Jupyter Notebook startup folder (Mac OS)

To launch Jupyter Notebook App:

  • Click on spotlight, type terminal to open a terminal window.
  • Enter the startup folder by typing cd /some_folder_name.
  • Type jupyter notebook to launch the Jupyter Notebook App The notebook interface will appear in a new browser window or tab.

3. From Jupyter notebook

jupyter notebook –help-all could be of help:

–notebook-dir=<Unicode> (NotebookManager.notebook_dir) Default: u’/Users/me/ipynbs’ The directory to use for notebooks.

For example:

jupyter notebook –notebook-dir=/Users/yourname/folder1/folder2/

You can of course set it in your profiles if needed, you might need to escape backslash in Windows.

Note that this will override whatever path you might have set in a jupyter_notebook_config.py file. (Where you can set a variable c.NotebookApp.notebook_dir that will be your default startup location.)

4. Configuration File

Assuming you have several conda environments you can set up default directories for each as follows.

  1. Open a terminal for one of your environments (not the default one). You can do that from the Anaconda Navigator ? Environments tab.
  2. If you don?t have a default configuration file, you need to create one by entering the command
  3. $ jupyter notebook –generate-config.
  4. This will create a default
  5. C:Usersusername.jupyterjupyter_notebook_config.py
  6. file (which will do nothing because everything is commented out in the file).
  7. Enter
  8. jupyter –paths.
  9. This lists the default paths for the environment you are working in. Look for the config path for your environment, e.g.
  10. config: … C:UsersusernameAnaconda3envsenvnameetcjupyter
  11. You?ll probably find the directory doesn?t exist. Create it.
  12. Copy your jupyter_notebook_config.py file into the …etcjupyter directory you just created.
  13. Edit the file ? you are looking for the ?c.NotebookApp.notebook_dir” entry. Enter the default directory path you want your notebook to open to. c.NotebookApp.notebook_dir = r”C:Usersusernamedefault_directory” (the ‘r’ string prefix saves you having to escape all the backslashes (the slashes go the other way in linux)). Uncomment the entry.

5. os.chdir(NEW_PATH)

Running os.chdir(NEW_PATH) will change the working directory.

import osos.getcwd()Out[2]:’/tmp’In [3]:os.chdir(‘/’)In [4]:os.getcwd()Out[4]:’/’In [ ]:

A recent video of How to Change Jupyter Notebook Startup Folder or Directory.

More information can be found here:

Starting terminal in current directory Issue #2018 jupyter/notebook

In the IPython notebook when I?m browsing the directory tree I often need to start a terminal in the directory I?m?

github.com

Please check my recently published articles:

?Python for finance series

  1. Identifying Outliers
  2. Identifying Outliers ? Part Two
  3. Identifying Outliers ? Part Three
  4. Stylized Facts
  5. Feature Engineering & Feature Selection
  6. Data Transformation
10

No Responses

Write a response