Skip to content


Notebook kernel crash when specifying --notebook-dir on commandline #886

fwerner opened this Issue · 8 comments

3 participants



I start a notebook server like this:

$ ipython notebook --notebook-dir="/home/fwerner/Documents/Notebooks" --pylab=inline

After loading a notebook in my browser, the kernel dies instantly. This is related to the notebook-dir alias, which you can see from the traceback---here's the full console output:

$ ipython notebook --notebook-dir="/home/fwerner/Documents/Notebooks" --pylab=inline --log-level=DEBUG --debug
[IPythonNotebookApp] Config changed:
[IPythonNotebookApp] {'Application': {'log_level': 10}, 'IPKernelApp': {'pylab': u'inline'}, 'NotebookManager': {'notebook_dir': u'/home/fwerner/Documents/Notebooks'}}
[IPythonNotebookApp] Using existing profile dir: u'/home/fwerner/.config/ipython/profile_default'
[IPythonNotebookApp] Searching path [u'/home/fwerner/Development/ipython', u'/home/fwerner/.config/ipython/profile_default'] for config files
[IPythonNotebookApp] Attempting to load config file:
[IPythonNotebookApp] Config file not found
[IPythonNotebookApp] Attempting to load config file:
[IPythonNotebookApp] Config file not found, skipping:
[IPythonNotebookApp] The port 8888 is already in use, trying another random port.
[IPythonNotebookApp] The IPython Notebook is running at:
WARNING:root:404 GET /static/mathjax/MathJax.js?config=TeX-AMS_HTML ( 0.44ms
[IPythonNotebookApp] Kernel started: e493215c-54f4-49a9-b8a9-a158ea272965
[IPythonNotebookApp] Connecting to: tcp://
[IPythonNotebookApp] Connecting to: tcp://
[IPythonNotebookApp] Connecting to: tcp://
WARNING: Unrecognized alias: 'notebook-dir', it will probably have no effect.Traceback (most recent call last):
  File "", line 1, in 
  File "IPython/zmq/", line 777, in main
  File "IPython/zmq/", line 710, in initialize
    super(IPKernelApp, self).initialize(argv)
  File "IPython/zmq/", line 279, in initialize
    super(KernelApp, self).initialize(argv)
  File "IPython/core/", line 306, in initialize
  File "IPython/config/", line 406, in parse_command_line
    config = loader.load_config()
  File "IPython/config/", line 575, in load_config
  File "IPython/config/", line 664, in _convert_to_config
  File "IPython/config/", line 496, in load_config
    self._exec_config_str(lhs, rhs)
  File "IPython/config/", line 347, in _exec_config_str
    exec exec_str in locals(), globals()
  File "", line 1
SyntaxError: can't assign to operator

The SyntaxError is thrown by the (assembled) statement


It seems to me that IPython shouldn't even try to run statements like this---or at least catch the SyntaxError and warn the user. But I think the real issue is that the notebook-dir alias isn't known at this point. Maybe it also doesn't have to be known, and the commandline argument should have been swallowed at an earlier stage?

Unfortunately, I'm not familiar enough with the codebase to proceed further.


IPython member

Actually, @minrk today fixed up that particular error, but the --notebook-dir option remains broken. In master, giving it produces an empty landing page even if the directory pointed to contains notebooks. And clicking the 'new notebook' button crashes the whole thing with:

ERROR:root:Uncaught exception GET /new (
HTTPRequest(protocol='http', host='', method='GET', uri='/new', version='HTTP/1.1', remote_ip='', body='', headers={'Accept-Language': 'en-us,en;q=0.5', 'Accept-Encoding': 'gzip, deflate', 'Host': '', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1', 'Accept-Charset': 'UTF-8,*', 'Connection': 'keep-alive', 'Referer': '', 'If-None-Match': '"5b68dcdf6f18fcfcc2be970584c3c45957e4abde"'})
Traceback (most recent call last):
  File "/home/fperez/usr/opt/lib/python2.7/site-packages/tornado-2.1.1-py2.7.egg/tornado/", line 954, in _execute
    getattr(self, self.request.method.lower())(*args, **kwargs)
  File "/home/fperez/usr/opt/lib/python2.7/site-packages/tornado-2.1.1-py2.7.egg/tornado/", line 1667, in wrapper
    return method(self, *args, **kwargs)
  File "/home/fperez/usr/lib/python2.7/site-packages/IPython/frontend/html/notebook/", line 77, in get
    notebook_id = self.application.notebook_manager.new_notebook()
  File "/home/fperez/usr/lib/python2.7/site-packages/IPython/frontend/html/notebook/", line 225, in new_notebook
    with open(path,'w') as f:
IOError: [Errno 2] No such file or directory: u'~/ipython/ipython/docs/examples/notebooks/Untitled0.ipynb'
ERROR:root:500 GET /new ( 1.12ms

Flagging as critical for 0.12, thanks for the report!


Hi again,

sorry for the trouble, I fixed the issue without realising it. Please take a look at this commit:


IPython member

Actually that change has already been made in master, see:

But the issue I pointed above remains, currently the --notebook-dir flag is indeed broken.


Sorry for the confusion---I only saw your comment after posting mine.

I cannot reproduce the issue you mentioned with the current master. Listing the notebooks in the specified directory works as expected, also creating/renaming/saving do.

IPython member

Ah, now I see. The crash only occurs in a very particular call form:

ipnb --notebook-dir=/home/fperez/tmp

works, and

ipnb --notebook-dir ~tmp

also works, but

ipnb --notebook-dir=~tmp

produces the crash. The reason is that in this last form, because of the = sign, the shell doesn't expand the ~ and neither do we. Since it's a reasonable call form, we just need to call expanduser(path) on the input path before processing it when passed with an = sign, or at least fail with a more informative error message than an iternal server error.

But I'm downgrading the severity of this issue, as it's now clear that the problem is only with parsing a very particular call form. thanks for the feedback!

IPython member

@fperez should the parser just always pass strings through expanduser on strings? It would appear that's what argparse is doing, so it makes sense to match.

IPython member
@minrk minrk added a commit that closed this issue
@minrk minrk Don't let invalid aliases crash IPython
e.g. `ipython --foo-bar=5` would raise a SyntaxError parsing the commmand-line, because `` would be evaluated.

Syntax Errors on the rhs were already protected, but they could get into the lhs via the alias syntax.

closes gh-886
@minrk minrk closed this in 11bca29
IPython member

home expansion and invalid-arg crashing both fixed.

@mattvonrocketstein mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue
@minrk minrk Don't let invalid aliases crash IPython
e.g. `ipython --foo-bar=5` would raise a SyntaxError parsing the commmand-line, because `` would be evaluated.

Syntax Errors on the rhs were already protected, but they could get into the lhs via the alias syntax.

closes gh-886
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.