Notebook: set the working directory

Created on 15 Feb 2017  路  4Comments  路  Source: jupyter/notebook

When I run jupyter notebook on my ubuntu ec2 instance, It does not open in my desired working directory. The way I used to do it is to navigate to my working directory and launch jupyter notebook from there. This way seem not to work anymore for me. I also tried jupyter notebook --notebook-dir=. from my desired directory but that does not seem to work too.

Most helpful comment

When I start a jupyter notebook server in app/, and then I open app/notebooks/Untitled.ipynb, the pwd of the kernel process is app/notebooks. The old behavior was that the kernel would be started in app/ just like the server was.

Is there a way to restore the old behavior?

All 4 comments

It should still pick up on the working directory where you launch it. This is working for me. Is it possible you have some config file which is overriding it? Run jupyter --paths to see where config can live.

When I start a jupyter notebook server in app/, and then I open app/notebooks/Untitled.ipynb, the pwd of the kernel process is app/notebooks. The old behavior was that the kernel would be started in app/ just like the server was.

Is there a way to restore the old behavior?

AFAIK the default has always been for the kernel's cwd to be the directory containing the notebook, so if it wasn't before, that was a bug.

There's no simple way to configure it - you'd need to subclass MappingKernelManager, override cwd_for_path(), and then set NotebookApp.kernel_manager_class.

This definitely didn't used to be the case for me. I'm using an iRuby kernel so perhaps the cwd code got moved from the specific kernel into the notebook core (sorry not super familiar with the architecture).

For those reading, here's a workaround:

$ cat ~/.ipython/kernels/ruby/kernel.json
{"argv":["/Users/rpatterson/.ipython/kernels/ruby/kernel.sh","{connection_file}"],"display_name":"Ruby","language":"ruby"}

$ cat ~/.ipython/kernels/ruby/kernel.sh
#!/bin/bash
cd "$(git rev-parse --show-toplevel)"
exec /Users/rpatterson/.rvm/bin/rvm . do bundle exec iruby kernel "$1"
Was this page helpful?
0 / 5 - 0 ratings