From e636c04941f0f1e8a14d5dc70ea54b5a76a65764 2012-06-23 00:39:15 From: Bradley M. Froehle Date: 2012-06-23 00:39:15 Subject: [PATCH] notebook: Print a warning (but do not abort) if no webbrowser can be found. Closes gh-2006. --- diff --git a/IPython/frontend/html/notebook/notebookapp.py b/IPython/frontend/html/notebook/notebookapp.py index 6f588ea..25ca0b4 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: