**
在本地访问jupyter notebook
**
在此感谢https://blog.youkuaiyun.com/qq_29762941/article/details/80630133该博主分享,该文完全只做实例分享
问题
jupyter notebook安装在服务器上,用xshell远程启动jupyter notebook,在本地浏览器打开jupyter显示无法访问
解决过程
操作环境:Ubuntu 18.10,Python 3.6.3
一、默认已下载好anaconda,若没下载,自行官网下载,anaconda集成了jupyter,anaconda下载官网
二、在当前用户的根目录创建一个名为nbserver的配置文件:
ipython profile create nbserver
三、进入该文件夹下进行配置:
cd ~/.ipython/profile_nbserver/
#ipython notebook要求https连接,创建ssl证书:
openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem
根据提示填写country name,province name之类信息,随意填写,不影响之后操作
四、启动ipython:
ipython
#创建远程连接密码:
from notebook.auth import passwd;
passwd()
#创建密码hash值的小程序,输入密码:
Enterpassword:(这是之后在本地浏览器,登陆服务器所需要的密码)
Verifypassword:
Out [2]: 'sha1:1df0132e4118:6adcf2a52950b..'#这个hash值要记住,之后要写入配置文件
exit()
五、编辑配置文件
vim ipython_notebook_config.py
#编辑内容
c=get_config()
c.IPKernelApp.pylab='inline' # 所有matplotlib的图像都通过iline的方式显示
c.NotebookApp.certfile=u'/home/XXX/.ipython/profile_nbserver/mycert.pem' #这一行指向我们刚刚创建的ssl证书,这里的路径要给绝对路径
c.NotebookApp.password=u'sha1:1df0132e4118:6adcf2a52950b.. '#创建的密码的哈希值
c.NotebookApp.ip='*'
c.NotebookApp.port=8888 # 给出运行的端口,ipython默认为8888
c.NotebookApp.open_browser=False # 禁止在运行ipython的同时弹出浏览器
保存:esc+":wq"
六、启动ipython Notebook的服务端了:
jupyter notebook --config=~/.ipython/profile_nbserver/ipython_notebook_config.py
七、在本地浏览器访问jupyter:
https://服务器IP:8888(这里就输入你服务器的IP地址,加上配置的端口号8888,注意前面的https不能省,省了会报错
我是在~/.ipython/profile_nbserver/ipython_notebook_config.py路径下启动的jupyter notebook,故浏览器显示的是该路径下文件
八、建议在用户根目录下启动jupyter notebook
cd ~
jupyter notebook --config=~/.ipython/profile_nbserver/ipython_notebook_config.py
[此时你就可以在根目录下进行操作]
注:每次启动jupyter notebook命令行太长,可以将该命令存为sh脚本,以后直接启动sh脚本即可:
vim jupyter.sh
jupyter notebook --config=~/.ipython/profile_nbserver/ipython_notebook_config.py
之后启动jupyter 直接:
sh jupyter.sh
注:本人该脚本在用户根目录下