如何更改 Jupyter 启动文件夹

Posted

技术标签:

【中文标题】如何更改 Jupyter 启动文件夹【英文标题】:How to change the Jupyter start-up folder 【发布时间】:2016-05-17 05:49:13 【问题描述】:

我尝试按照Jupyter Notebook documentation 上的说明进行操作。

不幸的是,我无法弄清楚。这个“起点”字段到底在哪里?

我有一个 Windows 7(64 位)系统,安装了 Anaconda3(不在 C 驱动器中)。我想更改 Jupyter 启动文件夹位置。

【问题讨论】:

在 Anaconda 下,还是一般情况下? GUI、命令行或两者兼而有之? 相关具体案例:How do I start jupyter notebook from command-line to run in my current directory, without editing config files or passing hard paths? 我的首选方法是使用命令cmd /c "cd C:\My\Desired\Folder & jupyter notebook" 创建一个.bat 并将其存储在某处。创建此 bat 文件的快捷方式 JupyterNB.bat - Shortcut。然后将此快捷方式复制到开始菜单文件夹,如%AppData%\Microsoft\Windows\Start Menu\Programs\Jupyter\JupyterNB.bat - Shortcut,以便在 Windows 菜单中快速启动。 【参考方案1】:

如果你是使用jupyter lab,想修改configure文件,需要更新的参数是:

c.ServerApp.root_dir = /path/to/directory/you/want

【讨论】:

【参考方案2】:

对于 Windows 用户,这里有一个 sn-p,可让您右键单击文件夹并在那里打开 Jupyter Lab。

def add_jupyter_to_context_menu(self):
    import winreg

    key = winreg.HKEY_CURRENT_USER
    command_value = rf'cmd.exe /k jupyter lab --notebook-dir="%V"'

    handle = winreg.CreateKeyEx(key, "Software\Classes\directory\Background\shell\Open with JupyterLab\command", 0,
                                winreg.KEY_SET_VALUE)
    winreg.SetValueEx(handle, "", 0, winreg.REG_SZ, command_value)

    # You need to download the icon yourself, or leave this part out for no icon
    icon_value = fr"C:\some_folder\jupyter_icon.ico"
    handle = winreg.CreateKeyEx(key, "Software\Classes\directory\Background\shell\Open with JupyterLab", 0,
                                winreg.KEY_SET_VALUE)
    winreg.SetValueEx(handle, "icon", 0, winreg.REG_SZ, icon_value)

def remove_jupyter_from_context_menu(self):
    import winreg
    key = winreg.HKEY_CURRENT_USER
    winreg.DeleteKey(key, "Software\Classes\directory\Background\shell\Open with JupyterLab\command")
    winreg.DeleteKey(key, "Software\Classes\directory\Background\shell\Open with JupyterLab")

【讨论】:

【参考方案3】:

截至 2021 年 12 月的今天,Jupyter 实验室对其配置文件进行了一些更改。因此,如果您遵循 Marneylc 的答案,这也是公认的答案,那么您应该寻找这一行

# c.ServerApp.root_dir = ''

而不是

#c.NotebookApp.notebook_dir = ''

在报价单中添加您想要的位置,它会正常工作?

【讨论】:

以上是关于如何更改 Jupyter 启动文件夹的主要内容,如果未能解决你的问题,请参考以下文章

如何启动jupyter 如何后台启动jupyter

修改jupyter notebook 启动工作路径的方法

当本地模块中的代码发生更改时,我是不是总是必须在 Jupyter Lab 中重新启动内核?

我在主页上有很多Jupyter笔记本,当Jupyter启动时会显示。我该如何清洁其中一些?

1在指定目录下启动Jupyter Notebook

【jupyter notebook】—— 安装和启动