?Tips and Tricks in Python
Photo by Dave Gandy under the Public Domain Dedication License
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.
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.
- Open a terminal for one of your environments (not the default one). You can do that from the Anaconda Navigator ? Environments tab.
- If you don?t have a default configuration file, you need to create one by entering the command
- $ jupyter notebook –generate-config.
- This will create a default
- file (which will do nothing because everything is commented out in the file).
- jupyter –paths.
- This lists the default paths for the environment you are working in. Look for the config path for your environment, e.g.
- config: … C:UsersusernameAnaconda3envsenvnameetcjupyter
- You?ll probably find the directory doesn?t exist. Create it.
- Copy your jupyter_notebook_config.py file into the …etcjupyter directory you just created.
- 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.
Running os.chdir(NEW_PATH) will change the working directory.
import osos.getcwd()Out:’/tmp’In :os.chdir(‘/’)In :os.getcwd()Out:’/’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?
Please check my recently published articles:
?Python for finance series
- Identifying Outliers
- Identifying Outliers ? Part Two
- Identifying Outliers ? Part Three
- Stylized Facts
- Feature Engineering & Feature Selection
- Data Transformation