脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - Jupyter Notebook 远程访问配置详解

Jupyter Notebook 远程访问配置详解

2021-08-24 00:03MachinePlay Python

这篇文章主要介绍了Jupyter Notebook 远程访问配置详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

问题

jupyter notebook可以说是非常好用的小工具,但是不经过配置只能够在本机访问
笔者参阅了文档对jupyter notebook进行配置,实现了跨主机浏览器访问

安装jupyter notebook

笔者使用conda包管理

?
1
conda install jupyter notebook

生成默认配置文件

?
1
jupyter notebook --generate-config

将会在用户主目录下生成.jupyter文件夹,其中jupyter_notebook_config.py就是刚刚生成的配置文件

生成秘钥

输入 ipython,进入ipyhon命令行
输入

?
1
2
3
in [1]: from notebook.auth import passwd
 
in [2]: passwd()

这里要求你输入以后登录使用的密码,然后生成一个秘钥,记得保存好秘钥,以免丢失。

?
1
2
3
enter password:
verify password:
out[2]: 'sha1:1b4ea9662b35:3e3d6a823d264d466f125a0939623c05e7b66007'

修改配置文件

修改用户主目录下~/.jupyter/jupyter_notebook_config.py文件
取消c.notebookapp.password = ''"注释,并将生成的秘钥复制进去

?
1
c.notebookapp.password = 'sha1:1b4ea9662b35:3e3d6a823d264d466f125a0939623c05e7b66007'

取消下面几项注释,并注释修改ip、端口、不自动打开浏览器

?
1
2
3
c.notebookapp.ip='*'#×允许任何ip访问
c.notebookapp.open_browser = false
c.notebookapp.port =8888 #可自行指定一个端口, 访问时使用该端口

如果是比较老的jupyter notebook版本还会有 allow_remote_access之类的一个设置,记得改成true并取消注释。
大功告成

测试

在服务器开启jupyter notebook

  • 浏览器不会自动开启
  • 其他电脑在浏览器输入服务器ip:8888,能够访问jupyter notebook

例,我服务器ip 192.168.199.219,笔记本ip 192.168.199.166
服务器输入

?
1
jupyter notebook

有如下提示

(tf1.12) yep@yepdlpc:~$ jupyter notebook
[i 00:10:58.671 notebookapp] writing notebook server cookie secret to /run/user/1000/jupyter/notebook_cookie_secret
[w 00:10:58.992 notebookapp] warning: the notebook server is listening on all ip addresses and not using encryption. this is not recommended.
[i 00:10:58.998 notebookapp] serving notebooks from local directory: /home/yep
[i 00:10:58.998 notebookapp] 0 active kernels
[i 00:10:58.998 notebookapp] the jupyter notebook is running at: http://[all ip addresses on your system]:8888/
[i 00:10:58.998 notebookapp] use control-c to stop this server and shut down all kernels (twice to skip confirmation).

在笔记本浏览器输入192.168.199.219:8888.
成功远程访问服务器的jupyter notebook

Jupyter Notebook 远程访问配置详解

后记

输入密码,接可以愉快的在笔记本写代码,在服务器跑代码啦
可以在jupyter开terminal,连ssh登陆都省了~~
不过如果服务器shell关闭后就无法访问了,可以在服务器后台运行jupyter notebook来避免这一问题

?
1
nohup jupyter notebook&

这样shell关闭也不会有问题啦

Jupyter Notebook 远程访问配置详解

到此这篇关于jupyter notebook 远程访问配置详解的文章就介绍到这了,更多相关jupyter notebook 远程访问内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://www.jianshu.com/p/3cc167bd63dd

延伸 · 阅读

精彩推荐