配置jupyter外网访问
1.使用jupyter notebook --generate-config生成jupyter配置文件。配置文件路径在/home/***/.jupyter(***为用户名)
2.jupyter notebook 5.0 版本开始,提供了一个命令来设置密码:jupyter notebook password,生成的密码存储在 jupyter_notebook_config.json
3.打开 jupyter_notebook_config.json把里面的sha1的值复制出来
4.在配置文件路径下新建jupyter_notebook_config.py,输入下面内容
c.NotebookApp.ip='*' #所有ip都可以访问
c.NotebookApp.password = u'sha1:f731047bde51:46793f9da6aee8244107c86aea5c89adf4359f38' #jupyter密码密文,从jupyter_notebook_config.json复制的sha1值
c.NotebookApp.open_browser = False #默认不打开浏览器(远程访问,本地不打开)
c.NotebookApp.port =8888 #端口
c.NotebookApp.notebook_dir = 'Desktop/JupyterProject/' #jupyter默认访问工作路径
5.远程访问方式:192.168.**.**:8888(ip:端口号)
配置jupyter多个kernel版本
1.使用jupyter kernelspec list查看当前jupyter已经安装的python kernel
2.在需要添加到jupyter中的python环境下使用pip install ipykernel
3.使用jupyter kernelspec list查看当前jupyter已经安装的python kernel,刚才添加的python版本已经添加进kernelspec 了
4.在/home/***/.local/share/jupyter/kernels/下,找到新添加的python版本文件夹,修改其中的配置文件kernel.json
{
"display_name": "Python 2", #在jupyter中显示的名字
"language": "python",
"argv": [
"/usr/bin/python2.7", #修改为需要添加的python路径。默认在/usr/bin下,虚拟环境可根据虚拟环境的路径进行配置
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
]
}
5.完成,打开jupyter,可以看到已经多了一个新的python版本的kernel。使用不同python版本的kernel新建jupyter文件,查看python版本是否正确
import sys
print(sys.version)