Skip to content
Home » How to change the Jupyter Notebook default directory

How to change the Jupyter Notebook default directory

Tags:

When I first started using notebooks, one of the letdowns was that I wasn’t able to navigate upwards out of the installation folder. I save all my projects on an extra internal hard disk drive, both for safety and portability. It’s also never a bad idea to have an additional backup (besides GitHub). Accessing these projects through my (Anaconda) Jupyter Notebooks seemed to be impossible. However, several solutions have been proposed on StackOverflow and other boards. Here’s a quick overview.

Throughout this blog post I’ll be using D:/python/foo as project folder. My Anaconda environment is data_science.

Solution 1: navigate to the folder and run Jupyter

The first solution is straightforward. You simply activate your environment, you browse to your project folder in the Anaconda Prompt, and you run Jupyter notebooks. It’s not a one-time solution. Every time you want to work on your project, you’ll have to retake these steps.

activate data_science
d:
cd python/foo
jupyter notebook

Solution 2: set the notebook-dir parameter

A faster solution (just one line of code) is to set the notebook-dir parameter when starting Jupyter notebook.

jupyter notebook --notebook-dir=D:/python/foo

Solution 3: edit the configuration file

A more permanent solution is editing the Jupyter configuration file. By running the following command in your Anaconda prompt, a file will be created (jupyter_notebook_config.py in your Jupyter installation folder).

jupyter notebook --generate-config

In this file, you’ll find c.NotebookApp.notebook_dir after a hash. Uncomment the line by removing the hash and set the value to the directory of your projects.

c.NotebookApp.notebook_dir = 'D:\python'

Now run Jupyter Notebook from the Anaconda prompt (or the Navigator), and you’ll start from your preferred directory. Keep in mind that you’ve changed the directory for every environment.

Another nuisance solved!

Say thanks, ask questions or give feedback

Technologies get updated, syntax changes and honestly… I make mistakes too. If something is incorrect, incomplete or doesn’t work, let me know in the comments below and help thousands of visitors.

9 thoughts on “How to change the Jupyter Notebook default directory”

  1. Thanks Roel.
    I’m using Debian 11 with Jupyter.

    It worked fine. But when I create a new notebook in the new directory, there is an error message, looking for the old directory.
    I wonder to know if there is another env-variable to change

    Sincerely

  2. Monitoruj telefon z dowolnego miejsca i zobacz, co dzieje się na telefonie docelowym. Będziesz mógł monitorować i przechowywać dzienniki połączeń, wiadomości, działania społecznościowe, obrazy, filmy, WhatsApp i więcej. Monitorowanie w czasie rzeczywistym telefonów, nie jest wymagana wiedza techniczna, nie jest wymagane rootowanie.

Leave a Reply

Your email address will not be published. Required fields are marked *