Anaconda 下更改 Jupyter notebook 默认启动路径

目录

  • 前言
  • 更换默认路径的方法
  • 注意事项
  • 配置 JupyterLab 或 Jupyter Notebook Classic 或 RetroLab
  • 参考链接


前言

Windows中,使用Anaconda中开启Jupyter Notebook时,默认的路径是~/,也就是C:/Users/[你的用户名]/。如何更改这个默认的路径呢?

一种稍欠优雅的方式是:先开启anaconda的命令行终端(如cmdpowershell),然后手动输入命令打开Jupyter notebook,同时指定开启时的根目录。命令如下:

jupyter notebook --notebook-dir=path/to/your/folder

比如,想要开启D:/盘符下的jupyter/文件夹时,就需要输入以下命令:

jupyter notebook --notebook-dir=D:/jupyter/

更换默认路径的方法

  1. 打开cmd或者Anacoda Prompt,进入对应的Anaconda环境(比如base
  2. 运行这个指令:jupyter notebook --generate-config,这个命令会在C:/Users/[你的用户名]/.jupyter/目录下创建可以自定义的配置文件 jupyter_notebook_config.py
  3. 在文本编辑器中打开上一步创建的 jupyter_notebook_config.py文件
  4. Ctrl+F 打开搜索框,找到 #c.NotebookApp.notebook_dir = ''所在的那行
  5. 去掉行首的#来解除注释,并且在行末的单引号内输入你想设定的文件夹目录(如:c.NotebookApp.notebook_dir = 'D:/jupyter')(如果此处出错,请查看文末的 注意事项 章节)
  6. 保存文件。

现在再次从anaconda中打开Jupyter notebook时,就会进入你指定的文件夹了(比如这里会是D:/jupyter)。

注意事项

  1. 指定路径时不要使用~/,而要使用完整路径,如 D:/jupyter
  2. 请在路径中使用正斜杠(/);如果路径被双引号引出,则可以使用反斜杠(\),并且此时路径中可以包含空格
  3. 记得删除文首的井号注释符(#),来让这一行命令生效

配置 JupyterLab 或 Jupyter Notebook Classic 或 RetroLab

对于JupyterLab(适用于版本>= 3的情况) 或 Jupyter Notebook ClassicRetroLab,请将上述方法中:

  1. 第二步的 jupyter notebook --generate-config 换为 jupyter server --generate-config
  2. 第四步的 c.NotebookApp.notebook_dir 换为 c.ServerApp.root_dir

详情请查看:
Notebook server 迁移指南
jupyter notebook 与 jupyter server 区别是什么


参考链接

How to change the Jupyter start-up folder - Stack overflow

你可能感兴趣的:(pyhton,python,jupyter,自然语言处理,opencv,tensorflow)