How to Change Working Directory in Jupyter Notebook
Jupyter notebook
Jupyter notebook

1. Installing Jupyter Notebook

Use pip or conda (Anaconda) to install Jupyter Notebook, if not installed already.

# Python 3
python3 -m pip install jupyter

#Python 2
python -m pip install jupyter

2. Start Notebook in the background

When the notebook command is executed, the server starts and a browser window is opened. The default working directory is the user’s home directory.



# Start notebook normally
jupyter notebook

# Start notebook and run in the background
jupyter notebook &> /dev/null &

3. Start Notebook with a custom working directory for a single session

Add the option --NotebookApp.notebook_dir to specify a working directory while starting the Notebook:

jupyter notebook --NotebookApp.notebook_dir=/Users/abc/Work/python

# You'll see a message like the following
# [I 11:47:46.507 NotebookApp] Serving notebooks from local directory: /Users/abc/Work/python

4. Start Notebook with a custom working directory always

In case you want to always start the Notebook with a specific working directory, instead of specifying it as an option in the shell command, you can specify the working directory in the config file.



Generate the config file if it does not exist. The typical location of the config file on Mac: ~/.jupyter/jupyter_notebook_config.py.

# Generate a config file if not existing already
jupyter notebook --generate-config

# Creates the folloiwng file
# ~/.jupyter/jupyter_notebook_config.py

# Modify the following key in the config file to specify the desired working directory
c.NotebookApp.notebook_dir = '/Users/abc/Work/python'

# Start notebook normally
jupyter notebook

# Or start notebook in the background
jupyter notebook &> /dev/null &


How to Change Working Directory in Jupyter Notebook
Be The First

Join our list to get instant access to new articles and weekly newsletter.

Tagged on:         
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x