前提已安装好Anaconda3
1、安装jupyterhub和notebook
$pip install jupyterhub notebook
2、安装configurable-http-proxy
$npm install -g configurable-http-proxy
如果没有npm命令,还需要安装npm
$yum install npm
如果在局域网中需要代理才能上网,npm还需要设置proxy。如果第2步的安装命令要用sudo,这里设置代理也需要加上sudo。
$npm config set proxy http://x.x.x.x:xxxx
$npm config set https-proxy http://x.x.x.x:xxxx
3、配置jupyterhub。在合适位置新建一个文件夹,比如/etc/jupyterhub,创建一个配置文件config.py,我输入了如下内容。c.Spawner.notebook_dir = '~/notebooks' 表示登录用户的默认notebook文件夹是home目录下的notebooks。一些额外的环境变量可以在c.Spawner.environment中指定,比如LD_LIBRARY_PATH。
c.Spawner.cmd = ['/anaconda3/bin/jupyterhub-singleuser']
c.Spawner.notebook_dir = '~/notebooks'
c.JupyterHub.ip = 'x.x.x.x'
c.JupyterHub.port = 8899
c.Spawner.env_keep = ['PATH', 'PYTHONPATH', 'CONDA_ROOT', 'CONDA_DEFAULT_ENV', 'VIRTUAL_ENV', 'LANG', 'LC_ALL']
c.Spawner.environment = {'LD_LIBRARY_PATH':'/lib/xxx/'}
其实还有很多配置,可以生成一个默认配置文件查看,具体命令:
$jupyterhub --generate-config -f /etc/jupyterhub/jupyterhub_config.py
4、配置notebook。用如下命令生成配置文件(会生成~/.jupyter/jupyter_notebook_config.py),根据需要修改配置文件即可
$jupyter notebook --generate-config
5、启动jupyterhub,如果都安装正确,jupyterhub应该就正常启动了。可以在浏览器中输入地址端口(http://x.x.x.x:8888)用linux用户名密码进行登录。启动命令如下:
/anaconda3/bin/jupyterhub --no-ssl -f /etc/jupyterhub/config.py
6、在jupyter 上 增加内核(bash_kernel)
$pip install bash_kernel
$python -m bash_kernel.install
遇到的问题:
1、用户登录的过程中报错:AttributeError: type object 'IOLoop' has no attribute 'initialized'进而造成Spawner failed to start [status=1]
解决办法:
$pip install --upgrade pyzmq notebook
2、用户登录后,创建新Python文件报错:AttributeError: module 'tornado.web' has no attribute 'asynchronous'
tornado版本不对,要回退到5.0,解决办法:
$pip uninstall tornado
$pip install tornado==5.0
nbconvert需要5.3.1版本,如果版本不对,也如上面那样重新安装。
这两个问题解决后,用户就可以成功登录使用jupyter-notebook了。
3、发现jupyter-notebook只能成功登录一次,退出后登录或者另一名用户登录会报如下错误:[PAM Error 7] Authentication failure
解决办法:
在启动jupyterhub的config文件中加入下面的设置:
c.PAMAuthenticator.open_sessions = False
4、启动jupyterhub时遇到ModuleNotFoundError: No module named 'ruamel'错误
解决办法:运行如下命令安装runamel.yaml
conda install -c conda-forge ruamel.yaml