我如何从命令行指定 jupyter notebooks 的工作目录

How can i specify the working directory for jupyter notebooks from the command line

我有一个带有 jupyter 笔记本的 python 项目,我想将它们保存在自己的子目录中(例如 jupyter_notebooks)。现在我想启动 jupyter,这样 notebooks 就会使用项目根目录作为 cwd 而不是它们所在的目录。像这样:

python -m jupyter --cwd=project\root

有办法吗?

我认为您正在寻找 --notebook-dir 参数:

python -m jupyter notebook --notebook-dir=/path/to/directory

或者只是:

jupyter notebook --notebook-dir=/path/to/directory

您可以通过 运行 jupyter notebook --help 查看命令的所有选项。

如果您希望笔记本服务器始终使用特定目录而不提供参数,您可以通过 运行:

为笔记本服务器生成一个配置文件
jupyter notebook --generate-config

创建文件的名称将打印到控制台。然后,在此文件中,取消注释 并编辑找到变量 c.NotebookApp.notebook_dir 的行,例如:

c.NotebookApp.notebook_dir = '/path/to/directory'