Customizing IPython default notebook location

Did some searching around and it turns out, the “easiest” way to do this is to simply navigate (using Terminal) to your desired notebook save location and then launching IPython (just enter the text that’s listed after the $):

samb@Mephisto:~$ ipython notebook

I’ve been using IPython for some months now and never realized that it was simply saving notebooks in my current working directory! Doh!  I could’ve just been changing to the desired directory this entire time!

Knowing this, I can just create a symbolic link to my desired default IPython directory and quickly change to the directory when starting IPython without having to go through a bunch of cd steps to get to the location.

However, if you have a default location you’d like IPython to save your IPyton notebooks to, I found out how to edit some of the IPython profile configuration files on this Stack Overflow entry.

Briefly, here’s what needs to be done.

1. Locate where IPython is installed, using Terminal.

Input:

samb@Mephisto:~$ ipython locate

Output:

/home/samb/.config/ipython

2. My IPython location did NOT contain an “ipython_notebook_config.py” file, so one had to be created. Oh, and to figure out that I did NOT have that Python (.py) file, I just navigated there using the GUI (Nautilus), but I did have to allow for viewing Hidden Files by pressing Ctrl-h. Used Terminal to create this files with the following command (and subsequent output):

The input:

samb@Mephisto:~$ ipython profile create

The output:

[ProfileCreate] Generating default config file: u'/home/samb/.config/ipython/profile_default/ipython_config.py'
[ProfileCreate] Generating default config file: u'/home/samb/.config/ipython/profile_default/ipython_notebook_config.py'

3. I opened my “ipython_notebook_config.py” file with the gedit program (the default program that opens text-based files when I double-click on them) and changed this:

# The directory to use for notebooks.
#c.NotebookManager.notebook_dir = u’/home/samb’

to this:

# The directory to use for notebooks.
c.NotebookManager.notebook_dir = u’/media/B0FE4B1FFE4ADD6A/Users/Samb/Dropbox/Lab/IPython_nbs’

Notice, I took out the hash/pound symbol (#) before the line that has the directory to my desired notebook save location, as the hash symbol indicates that a particular line should NOT be interpreted by whatever program is reading the file.

One thing I did notice is that the Stack Overflow entry indicates there should be two lines that need to be adjusted. However, my ipython_notebook_config.py file only had one of the two entries described, so I simply changed that. I’ll launch IPython and see what happens.

My expectation is that IPython will open and see the existing IPython notebooks in the directory I specified in the ipython_notebook_config.py.

The result?Workspace 1_010

It worked perfectly (see the area surrounded by the red rectangle)!

The biggest benefit of this setup is that I will now have a fixed file path for my IPython notebooks, whether I’m working at home, at work, or some other remote location.  After playing around some more, I may decide to set up a Git repository so that the IPython files are publicly accessible.  I’m also going to try out the Synology Cloud Station (basically the same as Dropbox) functionality on our lab’s server.  I think the latter might be ideal, since I’d be saving my IPython notebooks in our “web” folder, which is already publicly accessible.  But, using a Git repository would also have the benefit of version control, which might be nice.

Whatever the case, I can now quickly and easily modify the default IPython notebook save location!