【Python学习】Jupyter Lab 安装、使用、云服务器连接
·
1、安装
conda install -c conda-forge jupyterlab
或者:pip install jupyterlab
2、开启JupyterLab
jupyter lab
3、远程服务器连接
(1)安装JupyterLab/Jupyter Notebook
pip3 install jupyter jupyterlab
(2)ipython中为Jupyter服务配置密码
# ubuntu @ VM-0-16-ubuntu in ~ [20:02:19] C:127
$ ipython3
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
Type "copyright", "credits" or "license" for more information.
IPython 2.4.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: from notebook.auth import passwd
In [2]: passwd()
Enter password:
Verify password:
Out[2]: 'sha1:1e39d24dcd6c:b265321ca0c4cb798888bcb69b0024983a8ac439'
上边的输出中,‘sha1:’开头的这一串我们需要复制下来,一会儿配置的时候需要使用。而我们输入的密码就是我们在浏览器中登录Jupyter时需要输入的。
(3)接下来我们生成Jupyter配置文件并使用vim打开
# ubuntu @ VM-0-16-ubuntu in ~ [20:04:51]
$ jupyter lab --generate-config
Writing default config to: /home/root/.jupyter/jupyter_notebook_config.
# ubuntu @ VM-0-16-ubuntu in ~ [20:04:59]
$ vim /home/root/.jupyter/jupyter_notebook_config.py
(4)设置Jupyter配置文件
# 将ip设置为*,意味允许任何IP访问
c.NotebookApp.ip = '*'
# 这里的密码就是上边我们生成的那一串
c.NotebookApp.password = u'sha1:1e39d24dcd6c:b265321ca0c4cb798888bcb69b0024983a8ac439'
# 服务器上并没有浏览器可以供Jupyter打开
c.NotebookApp.open_browser = False
# 监听端口设置为8888或其他自己喜欢的端口
c.NotebookApp.port = 8888
# 我们可以修改jupyter的工作目录,也可以保持原样不变,如果修改的话,要保证这一目录已存在
c.MappingKernelManager.root_dir = '/home/ubuntu/.jupyter_run/root'
# 允许远程访问
c.NotebookApp.allow_remote_access = True
(5)启动jupyter服务
jupyter lab --allow-root
(6)本地映射
在window中打开cmd端口
ssh -N -f -L localhost:port1:localhost:port2 remote_user@remote_host -p port3
参数说明
port1:本地的浏览器端口
port2:远程服务器的浏览器端口
port3:SSH端口
(7)浏览器浏览
0.0.0.0:8888
温馨提示:使用云服务器连接的话,得现在云服务器的安全组中添加8888端口,否则无法访问
更多推荐
所有评论(0)