Default notebooks' directory for Jupyter launched from Anaconda Navigator

10,148

Solution 1

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

    $ jupyter notebook --generate-config.

    This will create a default

    C:\Users\username\.jupyter\jupyter_notebook_config.py

    file (which will do nothing because everything is commented out in the file).

  3. Enter

    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:\Users\username\Anaconda3\envs\envname\etc\jupyter

  4. You'll probably find the directory doesn't exist. Create it.
  5. Copy your jupyter_notebook_config.py file into the ...\etc\jupyter directory you just created.
  6. 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:\Users\username\default_directory" (the 'r' string prefix saves you having to escape all the backslashes (the slashes go the other way in linux)). Uncomment the entry.

And you should be good to go!

Solution 2

I don't know how to make this work for different environments, but here is how I was able to change the Jupyter default directory on Windows 7:

Check to see if you have a .jupyter directory in C:\Users\your_username. If so, then open jupyter_notebook_config.py. If not, then you can create it as follows:

  1. Open a command prompt (search for cmd from the Start button).
  2. At the prompt type jupyter notebook --generate-config

That should create the directory and the jupyter_notebook_config.py file. Now, find and uncomment the line (around line 195) that says c.NotebookApp.notebook_dir = '' and insert the directory name. The directory name should be entered between single quotes with forward slashes in place of the backslashes. For instance, mine looks like:

c.NotebookApp.notebook_dir = 'C:/Users/Tim/OneDrive/Python Files/' 

Now, start Anaconda Navigator as usual, launch Jupyter, and you should see that it is in your new default directory.

Solution 3

In Windows 10, either of the following will work:

  1. If you launch it using the shortcut installed by Anaconda3, go to

    C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Anaconda3 (32-bit)

    right-click on Jupyter Notebook (Anaconda3) and select 'Property' from menu; in the 'Target' and 'Atart in' fields, change %USERPROFILE%/ to point to your desirable directory;

  2. If you launch it from the command-shell opened by 'Anaconda Prompt (Anaconda3)', then simply type:

    jupyter notebook --notebook-dir "YOUR-DESIRABLE-DIRECTORY".

    Note: You must use double-quote, otherwise %USERPROFILE%/ was added to YOUR-DESIRABLE-DIRECTORY and fail to launch.

Solution 4

Here's an altenative which I have not seen anyone mentioned anywhere:

Keep the default directories all the same and simply create a bookmark in your browser.

For example, my python code is at C:\Users[name]\Documents\Code\Python, so I have a bookmark for "http://localhost:8888/tree/Documents/Code/Python" in my toolbar.

As soon as Jupyter opens a tab in your browser, hit the button. It requires one extra click, yes, but saves you from some possibly annoying tinkering, and allows you to create multiple such bookmarks!

Note: If I open Jupyter in a 2nd environment, I would need the same link but with 8889 (instead of 8888)

Solution 5

To get Anaconda Jupyter Notebook to show the folders in my D:\ drive when it launched, this is what I did:

open Anaconda command prompt (use the Anaconda menu and select Anaconda terminal)

  • OR launch Anaconda terminal directly from folder (Win 10), in similar location to: C:\Users\grant\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Anaconda3 (64-bit)\

this will show a command prompt similar to:

(base) C:\Users\grant>

change directory to D drive (i.e. the drive\folder you want to see when notebook launches):

(base) C:\Users\grant>D:

launch Jupyter notebook:

(base) D:\>jupyter notebook

For DIFFERENT ENVIRONMENTS do the following:

Assume you wanted to launch jupyter notebook with the R environment - where the notebook references the folders in drive D (as above):

open anaconda terminal and change to D drive (as above)

(base) C:\Users\grant>d:

view the environemnts that are available (and their paths):

(base) D:\>conda env list

    # conda environments:
    #
    base                  *  C:\Users\grant\Anaconda3
    R                        C:\Users\grant\Anaconda3\envs\R
    rstudio                  C:\Users\grant\Anaconda3\envs\rstudio

activate the required R environment

(base) D:\>activate C:\Users\grant\Anaconda3\envs\R

launch jupyter notebook showing the required drive folders (with the required R environment activated):

(R) D:\>jupyter notebook
Share:
10,148
MarianD
Author by

MarianD

Updated on June 04, 2022

Comments

  • MarianD
    MarianD almost 2 years

    I use Anaconda Navigator to launch Jupyter from different environments.

    The default directory for Jupyter notebooks (displayed just after the start of Jupyter) is my home directory (in Windows 7).

    Is it possible to set another directory as a default one, in the best case different for different environments? (For starting Jupyter from Anaconda Navigator?)

  • MarianD
    MarianD about 7 years
    Your solution is nice and new for me, so I voted your answer, thanks. Nevertheless I have 2 reservation about it: 1. It don't solve my problem with different environments (as you admitted). 2. It works only when I launch Jupyter directly (not from Anaconda Navigator).
  • Tim Mayes
    Tim Mayes about 7 years
    Interesting. I always launch Jupyter from Anaconda Navigator and this solution works for me. Maybe somebody else will have an idea of why it isn't working for you.
  • Tim Mayes
    Tim Mayes over 5 years
    Update: I just got a new Mac and while setting it up I used this exact procedure to set the default folder and it worked perfectly. The only difference on MacOS Mojave is that you use Terminal and that the config file will be (for me) /Users/tim/.jupyter/jupyter_notebook_config.py
  • SOK
    SOK almost 4 years
    Hi @Charles Gu. I am having a similar problem as i usually use the shortcut installed by Anaconda to launch Jupyter. When i go to the Target section from Properties it doesnt let me type the directory longer than a certain length. Im trying to type: 'C:/Users/Latitude User/Jupyter Notebooks/' but it is only letting me type in 'C:/Users/Latit. Any ideas?