From 7ae0c9482ffa37dc5bbda72b9fe4f1fc410e5643 Mon Sep 17 00:00:00 2001 From: "Bradley M. Froehle" Date: Fri, 22 Jun 2012 15:43:11 -0700 Subject: [PATCH] notebook: Print a warning (but do not abort) if no webbrowser can be found. Closes gh-2006. --- IPython/frontend/html/notebook/notebookapp.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/IPython/frontend/html/notebook/notebookapp.py b/IPython/frontend/html/notebook/notebookapp.py index 6f588ea51..25ca0b4f0 100644 --- a/IPython/frontend/html/notebook/notebookapp.py +++ b/IPython/frontend/html/notebook/notebookapp.py @@ -551,10 +551,11 @@ class NotebookApp(BaseIPythonApplication): if self.open_browser or self.file_to_run: ip = self.ip or '127.0.0.1' - if self.browser: - browser = webbrowser.get(self.browser) - else: - browser = webbrowser.get() + try: + browser = webbrowser.get(self.browser or None) + except webbrowser.Error as e: + self.log.warn('No web browser found: %s.' % e) + browser = None if self.file_to_run: filename, _ = os.path.splitext(os.path.basename(self.file_to_run)) @@ -566,10 +567,10 @@ class NotebookApp(BaseIPythonApplication): url = '' else: url = '' - b = lambda : browser.open("%s://%s:%i%s%s" % (proto, ip, - self.port, self.base_project_url, url), - new=2) - threading.Thread(target=b).start() + if browser: + b = lambda : browser.open("%s://%s:%i%s%s" % (proto, ip, + self.port, self.base_project_url, url), new=2) + threading.Thread(target=b).start() try: ioloop.IOLoop.instance().start() except KeyboardInterrupt: