最近为了练习Kaggle上的一篇数据分析案例“泰坦尼克乘客获取概率预测”,在windows上的jupyter notebook中各种报错(可能是依赖关系没配好),于是萌发了在现有开发测试debian8.5虚拟机上搭建anaconda2的想法。
1. Installing Jupyter Notebook
官网(https://jupyter.readthedocs.io/en/latest/install.html)建议使用Anaconda
1.1. 安装anaconda
wget下载,然后如下安装
bash Anaconda-latest-Linux-x86_64.sh
默认安装目录为用户家目录下的anaconda2,如:/home/omm/anaconda2
安装完成后就能执行jupyter notebook命令了,
列出anaconda当前包含哪些包:
conda -list
#我采用的是full安装,所有该命令将会显示206个包,
而此时ssh连接到虚拟机上执行jupyter notebook命令的话,jupyter服务默认监听本地8888端口(启动后默认打开命令行下的web浏览器),远端却无法浏览器连接到虚拟机的jupyter服务
2. 配置jupyter notebook 实现远程访问
2.1 生成jupyter配置文件
jupyter notebook --generate-config
2.2 配置访问jupyter密码保护
$ ipython
Python 2.7.13 |Anaconda 4.3.1 (64-bit)| (default, Dec 20 2016, 23:09:15)
Type "copyright", "credits" or "license" for more information.
IPython 5.1.0 -- 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:28ebb93ec41b:96830638e989cde7191b..................'
2.3 修改jupyter配置文件
$vim ~/.jupyter/jupyter_notebook_config.py
主要修改如下几个参数:
c.NotebookApp.ip='*'
c.NotebookApp.password = u'sha1:ce...粘贴上一步生成的密文'
c.NotebookApp.open_browser = False
c.NotebookApp.port =8888
2.4 启动jupyter
jupyter notebook
启动信息如下:
omm@debiansible:~$ jupyter notebook
[W 20:46:24.481 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[I 20:46:24.488 NotebookApp] Serving notebooks from local directory: /home/omm
[I 20:46:24.488 NotebookApp] 0 active kernels
[I 20:46:24.489 NotebookApp] The Jupyter Notebook is running at: http://[all ip addresses on your system]:8888/
[I 20:46:24.489 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
2.5 远程访问
访问地址http://ip:8888,输入2.2节配置的密码即可登录