jupyter notebook使用远程服务器方法

1、目标:在远程服务器的docker中运行jupyter notebook,在本地浏览器使用。

1.1、推荐使用Anaconda,创建虚拟环境,这样会自动安装jupyter notebook,就不需要自己安装了。安装anaconda 的方法参考这篇博客。
1.2 此处假设以及装好了anaconda,因此jupyter notebook以及可以启动了。

source activate 环境名

2、配置jupyter notebook可以远程访问。
2.1 输入下列命令,生成配置文件

jupyter-notebook --generate-config

执行下列命令设置密码

jupyter-notebook password

2.2打开文件复制密码:

vim /root/.jupyter/jupyter_notebook_config.json

2.3 配置文件

vim /root/.jupyter/jupyter_notebook_config.py

在文件最后加上:以下代码

c.NotebookApp.ip='*'
#允许通过任意绑定的服务器的ip访问
c.NotebookApp.port =8870#这个端口是docker容器和宿主机的映射端口
c.NotebookApp.open_browser=False
#不自动打开浏览器
c.NotebookApp.password=u'刚才复制的很长的那个密码'

2.4 容器内启动jupyter
首先查看ssh是否启动:

service ssh status

如果没启动会显示

sshd is not running

此时需要重新启动ssh服务:

sudo service ssh restart
jupyter notebook --ip=0.0.0.0 --allow-root

2.5在本地浏览器访问:

宿主机IP:刚才设置的端口号

即可实现远程访问。如果要在后台运行,2.4步骤应该改为以下命令,可以后台运行。

nohup  jupyter notebook --ip=0.0.0.0 --allow-root  >>out.log 2>&1 &

3、在jupyter中切换conda虚拟环境的方法,在虚拟环境中安装下面的包即可。

conda install nb_conda_kernels

4、自动补全功能

pip install jupyter_contrib_nbextensions -i https://pypi.tuna.tsinghua.edu.cn/simple

jupyter contrib nbextension install --user

pip install jupyter_nbextensions_configurator -i https://pypi.tuna.tsinghua.edu.cn/simple

jupyter nbextensions_configurator enable --user

jupyter notebook使用远程服务器方法_第1张图片

你可能感兴趣的:(Anaconda,python,jupyter,服务器,python)