Jupyter 远程配置

less than 1 minute read

Published:

1. 安装Anaconda,随后下载Jupyter

pip3 install jupyter

2. 生成notebook配置文件

执行以下命令,会在用户目录下生成的配置文件 .jupyter/jupyter_notebook_config.py,之后在这个文件中再进行配置

jupyter notebook --generate-config

3. 生成密码

输入下面的命令,会在用户目录下生成一个保存有密码的哈希值的 json文件, .jupyter/jupyter_notebook_config.json

jupyter notebook password

4. 修改配置文件

在用户目录下的 .jupyter/jupyter_notebook_config.py中找到下面几行取消注释并修改,这几行分别对应修改可以访问的ip、启动 jupyter notebook时是否开启浏览器,以及 jupyter notebook服务对应的接口, 其实直接将下面的几行复制到文件也可以

c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False
c.NotebookApp.port = 10086
c.NotebookApp.allow_remote_access = True
# Windows 下
c.NotebookApp.token = ''

5. 启动jupyter notebook并在后台运行

Linux

使用 nohup命令后台运行 jupyter notebook,并将输出的内容追加的内容输出到 jupyter.out文件中,同时将错误信息也输出到文件中。

nohup jupyter notebook >>jupyter.out 2>&1 &

Windows

新建文本文件 jupyter.bat (以bat结尾就行),输入以下代码,倒数第二行的 D:\Jupyter_workspace修改为你想要作为根目录的路径

%隐藏cmd窗口%
@echo off
if "%1"=="h" goto begin
start mshta vbscript:createobject("wscript.shell").run("""%~nx0"" h",0)(window.close)&&exit
:begin
cd /d D:\Jupyter_workspace
start /b jupyter notebook >nul 2>nul