首页 > 解决方案 > 修改 Jupyter 主目录的问题

问题描述

有一次,我将 Jupyter 主目录设置为~/Dropbox 不幸的是,由于 Dropbox 更改其文件夹名称的方式,该位置现在是我机器上指向隐藏目录的符号链接。这会导致 Jupyter 中出现以下错误

Refusing to serve hidden directory '/Users/alex/Dropbox', via 404 Error

很好......我现在想更改我的 Jupyter 主目录,但我遇到的问题是我无法弄清楚它当前的设置位置。

我已经检查过我的~/.jupyter/jupyter_notebook_config.py,但这似乎与默认值相同。

的输出$jupyter --paths是:

config:
    /Users/alex/.jupyter
    /usr/local/Cellar/python@2/2.7.14_3/Frameworks/Python.framework/Versions/2.7/etc/jupyter
    /usr/local/etc/jupyter
    /etc/jupyter
data:
    /Users/alex/Library/Jupyter
    /usr/local/Cellar/python@2/2.7.14_3/Frameworks/Python.framework/Versions/2.7/share/jupyter
    /usr/local/share/jupyter
    /usr/share/jupyter
runtime:
    /Users/alex/Library/Jupyter/runtime

有趣的是,以下目录不存在。

/usr/local/Cellar/python@2/2.7.14_3/Frameworks/Python.framework/Versions/2.7/etc/jupyter
/usr/local/etc/jupyter
/etc/jupyter

设置似乎没有效果c.NotebookApp.notebook_dir = '/Users/alex/'/Users/alex/.jupyter/jupyter_notebook_config.py

$jupyter notebook
[I 18:26:34.756 NotebookApp] [nb_conda_kernels] enabled, 4 kernels found
[I 18:26:35.257 NotebookApp] The port 8888 is already in use, trying another port.
[I 18:26:35.258 NotebookApp] The port 8889 is already in use, trying another port.
[I 18:26:35.259 NotebookApp] The port 8890 is already in use, trying another port.
[I 18:26:35.260 NotebookApp] The port 8891 is already in use, trying another port.
[I 18:26:36.299 NotebookApp] [nb_anacondacloud] enabled
[I 18:26:36.304 NotebookApp] [nb_conda] enabled
[I 18:26:36.382 NotebookApp] ✓ nbpresent HTML export ENABLED
[W 18:26:36.382 NotebookApp] ✗ nbpresent PDF export DISABLED: No module named 'nbbrowserpdf'
[I 18:26:36.388 NotebookApp] Serving notebooks from local directory: /Users/alex
[I 18:26:36.388 NotebookApp] 0 active kernels
[I 18:26:36.388 NotebookApp] The Jupyter Notebook is running at:
[I 18:26:36.388 NotebookApp] http://localhost:8892/?token=289948463daed06187325be63202f620b812dddc14f2918a
[I 18:26:36.388 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 18:26:36.389 NotebookApp] 

    Copy/paste this URL into your browser when you connect for the first time,
    to login with a token:
        http://localhost:8892/?token=289948463daed06187325be63202f620b812dddc14f2918a
[I 18:26:36.717 NotebookApp] Accepting one-time-token-authenticated connection from ::1
[I 18:26:37.252 NotebookApp] Refusing to serve hidden directory '/Users/alex/Dropbox', via 404 Error
[W 18:26:37.252 NotebookApp] 404 GET /api/contents?type=directory&_=1526088397023 (::1): directory does not exist: 'Dropbox'
[W 18:26:37.252 NotebookApp] directory does not exist: 'Dropbox'
[W 18:26:37.253 NotebookApp] 404 GET /api/contents?type=directory&_=1526088397023 (::1) 15.70ms referer=http://localhost:8892/tree

Jupyter 主目录可以从哪里设置?

标签: jupyter-notebookjupyterjupyter-lab

解决方案


这是从隐藏文件夹启动时抛出 404jupyter notebook的预期行为。

通常,jupyter notebook将在您调用jupyter notebook命令的文件夹中启动。所以cd进入你希望它运行的目录,并在jupyter notebook那里发出。

如果这不起作用,您可以尝试使用命令行参数(如jupyter notebook --notebook-dir=NEWDIR.

否则,您会在上面提到一个全局配置和一个本地(每个用户)配置。如果本地是默认值,那么您可能之前更改了全局配置。如果您将本地配置更改~/.jupyter/jupyter_notebook_config.py为应该覆盖全局配置的新值。

要清理全局配置,请在 Unix 或/etc/jupyterWindows中查找它。/usr/local/etc/jupyter/%PROGRAMDATA%\jupyter\

您可以列出与命令一起使用的当前配置路径jupyter --paths手册中的更多信息。


推荐阅读