[Anaconda] Jupyter Notebook 更改默认浏览器 / Change Jupyter Notebook Default Browser

闲谈 Digressions

   
   

@ZYX 写于2020年10月19日

Jupyter Notebook 更改默认浏览器 / Change Jupyter Notebook Default Browser

Steps

  1. Generate jupyter notebook config through CMD. 通过命令行生成jupyter notebook的配置文件
    >jupyter notebook --generate-config

    • The config file jupyter_notebook_config.py will be generated in the (user directory) /.jupyter directory. 配置文件将生成在 (用户目录) / .jupyter 目录下

  1. Modify jupyter_notebook_config.py. 修改jupyter_notebook_config.py文件
    • assign browswer path to c.NotebookApp.browser. 把浏览器程序地址赋给c.NotebookApp.browser
      • need to uncomment that line. 需要把那一行注释改成语句
      • do not ignor %s. %s不可省略
    • Original 未修改
      ## Specify what command to use to invoke a web browser when opening the notebook.
      #  If not specified, the default browser will be determined by the `webbrowser`
      #  standard library module, which allows setting of the BROWSER environment
      #  variable to override it.
      #  Default: ''
      #  c.NotebookApp.browser = ''
      
    • Modified 修改后
      ## Specify what command to use to invoke a web browser when opening the notebook.
      #  If not specified, the default browser will be determined by the `webbrowser`
      #  standard library module, which allows setting of the BROWSER environment
      #  variable to override it.
      #  Default: ''
      c.NotebookApp.browser = u'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
      
  2. Save and reopen jupyter notebook. 保存,之后jupyter notebook就会使用指定的浏览器了

Underlying Problems 可能的问题

1. The browser is sill unchanged. 依然未更改浏览器

Check whether you have uncommented the code.
检查那行代码是不是仍然是注释

2. Jupyter Notebook cannot find the browser. 提示没有找到浏览器

  1. Check whether the path is correct. 检查浏览器路径是否正确
  2. Check whether string format is correct. 检查字符串格式是否正确
    1. should use u'' to explictly convert to unicode. 需要使用u''来转换成unicode字符串
    2. should add %s at the end of the string. 需要在字符串末尾添加%s