jupyter notebook/lab 远程访问配置
- 运行命令,生成jupyter notebook的配置文件
jupyter notebook --generate-config
jupyter lab --generate-config
得到结果:
Writing default config to: /home/*YOURUSERNAME*/.jupyter/jupyter_notebook_config.py
Writing default config to: /home/*YOURUSERNAME*/.jupyter/jupyter_lab_config.py
虽然配置notebook后,lab会默认使用notebook的配置,但是会报警,强迫症表示受不了,就生成一份吧!
如下的配置基本一样,只不过lab对应的是c.ServerApp.
配置的属性是相同的。
- 打开Python/Ipython shell,运行
from notebook.auth import passwd;passwd()
或者直接在bash中运行:
python -c "from notebook.auth import passwd;print(passwd())"
会生成一串’type:salt:hashed-password’格式的哈希密码,复制一下,后面要添加到配置文件中。
注意,最近在进行配置的时候,上面的方法在lab没有成功,暂时没有进一步研究是哪一个地方出问题了,解决方式是直接在打开的时候指定token
:
jupyter lab --ServerApp.token="yourpassword"
- 打开jupyter 配置文件
import webbrowser
webbrowser.register( "chrome", None, webbrowser.GenericBrowser("your\chrome\path\chrome.exe"))
## The port the notebook server will listen on.
c.NotebookApp.port = 0000
# The string should be of the form type:salt:hashed-password.
c.NotebookApp.password = 'the hashed password string'
## Whether to open in a browser after starting. The specific browser used is
# platform dependent and determined by the python standard library `webbrowser`
# module, unless it is overridden using the --browser (NotebookApp.browser)
# configuration option.
#c.NotebookApp.open_browser = False
c.NotebookApp.browser = 'chrome'
## Dict of Python modules to load as notebook
## The directory to use for notebooks and kernels.
c.NotebookApp.notebook_dir = '/home/ubuntu/jupyter'
## The IP address the notebook server will listen on.
c.NotebookApp.ip = '*'
c.NotebookApp.allow_root = True
## Supply overrides for terminado. Currently only supports "shell_command".
# Default: {}
# linux环境下,指定“/bin/bash”
# win10环境下,要指定路径,此处bash.exe已经添加到环境变量中
c.ServerApp.terminado_settings = {"shell_command":"bash.exe"}
或者直接粘贴:
c.NotebookApp.ip = '*'
c.NotebookApp.port = 0000
c.NotebookApp.password = 'the hashed password string'
c.NotebookApp.notebook_dir = '/home/ubuntu/jupyter'
c.NotebookApp.open_browser = False
c.NotebookApp.allow_root = True
- 运行jupyter notebook,会显示ip及port。输入浏览器,即可出现登陆界面,输入密码即可。