清风徐来
Michael's Blog
Jupyter Notebook 在 CentOS7 下的安装配置

使用Jupyter在浏览器上快(ku)乐(bi)的 编码吧 jupyter.png 如果手头没有电脑,只有手机和 Pad ,却想用 python 写点东西(也许只是验证一下),这时就需要 Jupyter 了。(当然也可以直接用 Terminal 工具连上服务器搞起,也是一种解决方式,就是稍微繁琐点)。

好吧,我们开始安装 Jupyter之旅。先到官网版本库看看 https://repo.continuum.io/archive/,找到适合的最新版,复制链接地址(Mike 以 Linux 为例)。

$ wget https://repo.continuum.io/archive/Anaconda3-4.4.0-Linux-x86_64.sh
--2017-09-04 09:15:29--  https://repo.continuum.io/archive/Anaconda3-4.4.0-Linux-x86_64.sh
Resolving repo.continuum.io (repo.continuum.io)... 104.16.19.10, 104.16.18.10, 2400:cb00:2048:1::6810:130a, ...
Connecting to repo.continuum.io (repo.continuum.io)|104.16.19.10|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 523283080 (499M) [application/x-sh]
Saving to: ‘Anaconda3-4.4.0-Linux-x86_64.sh’

100%[=================================================================>] 523,283,080 11.3MB/s   in 59s    

2017-09-04 09:16:29 (8.39 MB/s) - ‘Anaconda3-4.4.0-Linux-x86_64.sh’ saved [523283080/523283080]

下载完成,vps 速度还算及格。

$ sudo bash Anaconda3-4.4.0-Linux-x86_64.sh
Welcome to Anaconda3 4.4.0 (by Continuum Analytics, Inc.)

In order to continue the installation process, please review the license
agreement.
Please, press ENTER to continue
>>> 
===================================
Anaconda End User License Agreement
===================================

Copyright 2017, Continuum Analytics, Inc.
.......
协议内容省略...
.......

Do you approve the license terms? [yes|no]
>>> yes

Anaconda3 will now be installed into this location:
/root/anaconda3

  - Press ENTER to confirm the location
  - Press CTRL-C to abort the installation
  - Or specify a different location below

[/root/anaconda3] >>> /data/anaconda3
PREFIX=/data/anaconda3
installing: python-3.6.1-2 ...
installing: _license-1.1-py36_1 ...
installing: alabaster-0.7.10-py36_0 ...
installing: anaconda-client-1.6.3-py36_0 ...
installing: anaconda-navigator-1.6.2-py36_0 ...
installing: anaconda-project-0.6.0-py36_0 ...
installing: asn1crypto-0.22.0-py36_0 ...
installing: astroid-1.4.9-py36_0 ...
installing: astropy-1.3.2-np112py36_0 ...
installing: babel-2.4.0-py36_0 ...
installing: backports-1.0-py36_0 ...
installing: beautifulsoup4-4.6.0-py36_0 ...
installing: bitarray-0.8.1-py36_0 ...
installing: blaze-0.10.1-py36_0 ...
installing: bleach-1.5.0-py36_0 ...
installing: bokeh-0.12.5-py36_1 ...
installing: boto-2.46.1-py36_0 ...
installing: bottleneck-1.2.1-np112py36_0 ...
installing: cairo-1.14.8-0 ...
installing: cffi-1.10.0-py36_0 ...
installing: chardet-3.0.3-py36_0 ...
installing: click-6.7-py36_0 ...
installing: cloudpickle-0.2.2-py36_0 ...
installing: clyent-1.2.2-py36_0 ...
installing: colorama-0.3.9-py36_0 ...
installing: contextlib2-0.5.5-py36_0 ...
installing: cryptography-1.8.1-py36_0 ...
installing: curl-7.52.1-0 ...
installing: cycler-0.10.0-py36_0 ...
installing: cython-0.25.2-py36_0 ...
installing: cytoolz-0.8.2-py36_0 ...
installing: dask-0.14.3-py36_1 ...
installing: datashape-0.5.4-py36_0 ...
installing: dbus-1.10.10-0 ...
installing: decorator-4.0.11-py36_0 ...
installing: distributed-1.16.3-py36_0 ...
installing: docutils-0.13.1-py36_0 ...
installing: entrypoints-0.2.2-py36_1 ...
installing: et_xmlfile-1.0.1-py36_0 ...
installing: expat-2.1.0-0 ...
installing: fastcache-1.0.2-py36_1 ...
installing: flask-0.12.2-py36_0 ...
installing: flask-cors-3.0.2-py36_0 ...
installing: fontconfig-2.12.1-3 ...
installing: freetype-2.5.5-2 ...
installing: get_terminal_size-1.0.0-py36_0 ...
installing: gevent-1.2.1-py36_0 ...
installing: glib-2.50.2-1 ...
installing: greenlet-0.4.12-py36_0 ...
installing: gst-plugins-base-1.8.0-0 ...
installing: gstreamer-1.8.0-0 ...
installing: h5py-2.7.0-np112py36_0 ...
installing: harfbuzz-0.9.39-2 ...
installing: hdf5-1.8.17-1 ...
installing: heapdict-1.0.0-py36_1 ...
installing: html5lib-0.999-py36_0 ...
installing: icu-54.1-0 ...
installing: idna-2.5-py36_0 ...
installing: imagesize-0.7.1-py36_0 ...
installing: ipykernel-4.6.1-py36_0 ...
installing: ipython-5.3.0-py36_0 ...
installing: ipython_genutils-0.2.0-py36_0 ...
installing: ipywidgets-6.0.0-py36_0 ...
installing: isort-4.2.5-py36_0 ...
installing: itsdangerous-0.24-py36_0 ...
installing: jbig-2.1-0 ...
installing: jdcal-1.3-py36_0 ...
installing: jedi-0.10.2-py36_2 ...
installing: jinja2-2.9.6-py36_0 ...
installing: jpeg-9b-0 ...
installing: jsonschema-2.6.0-py36_0 ...
installing: jupyter-1.0.0-py36_3 ...
installing: jupyter_client-5.0.1-py36_0 ...
installing: jupyter_console-5.1.0-py36_0 ...
installing: jupyter_core-4.3.0-py36_0 ...
installing: lazy-object-proxy-1.2.2-py36_0 ...
installing: libffi-3.2.1-1 ...
installing: libgcc-4.8.5-2 ...
installing: libgfortran-3.0.0-1 ...
installing: libiconv-1.14-0 ...
installing: libpng-1.6.27-0 ...
installing: libsodium-1.0.10-0 ...
installing: libtiff-4.0.6-3 ...
installing: libtool-2.4.2-0 ...
installing: libxcb-1.12-1 ...
installing: libxml2-2.9.4-0 ...
installing: libxslt-1.1.29-0 ...
installing: llvmlite-0.18.0-py36_0 ...
installing: locket-0.2.0-py36_1 ...
installing: lxml-3.7.3-py36_0 ...
installing: markupsafe-0.23-py36_2 ...
installing: matplotlib-2.0.2-np112py36_0 ...
installing: mistune-0.7.4-py36_0 ...
installing: mkl-2017.0.1-0 ...
installing: mkl-service-1.1.2-py36_3 ...
installing: mpmath-0.19-py36_1 ...
installing: msgpack-python-0.4.8-py36_0 ...
installing: multipledispatch-0.4.9-py36_0 ...
installing: navigator-updater-0.1.0-py36_0 ...
installing: nbconvert-5.1.1-py36_0 ...
installing: nbformat-4.3.0-py36_0 ...
installing: networkx-1.11-py36_0 ...
installing: nltk-3.2.3-py36_0 ...
installing: nose-1.3.7-py36_1 ...
installing: notebook-5.0.0-py36_0 ...
installing: numba-0.33.0-np112py36_0 ...
installing: numexpr-2.6.2-np112py36_0 ...
installing: numpy-1.12.1-py36_0 ...
installing: numpydoc-0.6.0-py36_0 ...
installing: odo-0.5.0-py36_1 ...
installing: olefile-0.44-py36_0 ...
installing: openpyxl-2.4.7-py36_0 ...
installing: openssl-1.0.2l-0 ...
installing: packaging-16.8-py36_0 ...
installing: pandas-0.20.1-np112py36_0 ...
installing: pandocfilters-1.4.1-py36_0 ...
installing: pango-1.40.3-1 ...
installing: partd-0.3.8-py36_0 ...
installing: path.py-10.3.1-py36_0 ...
installing: pathlib2-2.2.1-py36_0 ...
installing: patsy-0.4.1-py36_0 ...
installing: pcre-8.39-1 ...
installing: pep8-1.7.0-py36_0 ...
installing: pexpect-4.2.1-py36_0 ...
installing: pickleshare-0.7.4-py36_0 ...
installing: pillow-4.1.1-py36_0 ...
installing: pip-9.0.1-py36_1 ...
installing: pixman-0.34.0-0 ...
installing: ply-3.10-py36_0 ...
installing: prompt_toolkit-1.0.14-py36_0 ...
installing: psutil-5.2.2-py36_0 ...
installing: ptyprocess-0.5.1-py36_0 ...
installing: py-1.4.33-py36_0 ...
installing: pycosat-0.6.2-py36_0 ...
installing: pycparser-2.17-py36_0 ...
installing: pycrypto-2.6.1-py36_6 ...
installing: pycurl-7.43.0-py36_2 ...
installing: pyflakes-1.5.0-py36_0 ...
installing: pygments-2.2.0-py36_0 ...
installing: pylint-1.6.4-py36_1 ...
installing: pyodbc-4.0.16-py36_0 ...
installing: pyopenssl-17.0.0-py36_0 ...
installing: pyparsing-2.1.4-py36_0 ...
installing: pyqt-5.6.0-py36_2 ...
installing: pytables-3.3.0-np112py36_0 ...
installing: pytest-3.0.7-py36_0 ...
installing: python-dateutil-2.6.0-py36_0 ...
installing: pytz-2017.2-py36_0 ...
installing: pywavelets-0.5.2-np112py36_0 ...
installing: pyyaml-3.12-py36_0 ...
installing: pyzmq-16.0.2-py36_0 ...
installing: qt-5.6.2-4 ...
installing: qtawesome-0.4.4-py36_0 ...
installing: qtconsole-4.3.0-py36_0 ...
installing: qtpy-1.2.1-py36_0 ...
installing: readline-6.2-2 ...
installing: requests-2.14.2-py36_0 ...
installing: rope-0.9.4-py36_1 ...
installing: ruamel_yaml-0.11.14-py36_1 ...
installing: scikit-image-0.13.0-np112py36_0 ...
installing: scikit-learn-0.18.1-np112py36_1 ...
installing: scipy-0.19.0-np112py36_0 ...
installing: seaborn-0.7.1-py36_0 ...
installing: setuptools-27.2.0-py36_0 ...
installing: simplegeneric-0.8.1-py36_1 ...
installing: singledispatch-3.4.0.3-py36_0 ...
installing: sip-4.18-py36_0 ...
installing: six-1.10.0-py36_0 ...
installing: snowballstemmer-1.2.1-py36_0 ...
installing: sortedcollections-0.5.3-py36_0 ...
installing: sortedcontainers-1.5.7-py36_0 ...
installing: sphinx-1.5.6-py36_0 ...
installing: spyder-3.1.4-py36_0 ...
installing: sqlalchemy-1.1.9-py36_0 ...
installing: sqlite-3.13.0-0 ...
installing: statsmodels-0.8.0-np112py36_0 ...
installing: sympy-1.0-py36_0 ...
installing: tblib-1.3.2-py36_0 ...
installing: terminado-0.6-py36_0 ...
installing: testpath-0.3-py36_0 ...
installing: tk-8.5.18-0 ...
installing: toolz-0.8.2-py36_0 ...
installing: tornado-4.5.1-py36_0 ...
installing: traitlets-4.3.2-py36_0 ...
installing: unicodecsv-0.14.1-py36_0 ...
installing: unixodbc-2.3.4-0 ...
installing: wcwidth-0.1.7-py36_0 ...
installing: werkzeug-0.12.2-py36_0 ...
installing: wheel-0.29.0-py36_0 ...
installing: widgetsnbextension-2.0.0-py36_0 ...
installing: wrapt-1.10.10-py36_0 ...
installing: xlrd-1.0.0-py36_0 ...
installing: xlsxwriter-0.9.6-py36_0 ...
installing: xlwt-1.2.0-py36_0 ...
installing: xz-5.2.2-1 ...
installing: yaml-0.1.6-0 ...
installing: zeromq-4.1.5-0 ...
installing: zict-0.1.2-py36_0 ...
installing: zlib-1.2.8-3 ...
installing: anaconda-4.4.0-np112py36_0 ...
installing: conda-4.3.21-py36_0 ...
installing: conda-env-2.6.0-0 ...
Python 3.6.1 :: Continuum Analytics, Inc.
creating default environment...
installation finished.
Do you wish the installer to prepend the Anaconda3 install location
to PATH in your /root/.bashrc ? [yes|no]
[no] >>> 

You may wish to edit your .bashrc or prepend the Anaconda3 install location:

$ export PATH=/data/anaconda3/bin:$PATH

Thank you for installing Anaconda3!

Share your notebooks and packages on Anaconda Cloud!
Sign up for free: https://anaconda.org

根据提示输入 yes 及安装路径等(Mike 安装到了 /data/anaconda3, 还记得前两天刚刚的挂载 mount 吧,/data 有20G 呢)直到安装完毕。

$ export PATH=/data/anaconda3/bin:$PATH

$ jupyter notebook --generate-config
Writing default config to: /home/你的用户名/.jupyter/jupyter_notebook_config.py

创建好了,配置文件,就去产生个访问 Jupyter 的密码。

$ python
Python 3.6.1 |Anaconda 4.4.0 (64-bit)| (default, May 11 2017, 13:09:58) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from notebook.auth import passwd
>>> passwd()
Enter password: 
Verify password: 
'sha1:9c252a7bae90:23bf013a345e05be0b74a2xxxxxx'
>>> exit()

$ vi /home/centos/.jupyter/jupyter_notebook_config.py 

编辑配置文件,加入以下。可以自行调整,*,代表可以从任何 ip 来访问 jupyter,password 就是刚刚生成的,port 就是你想通过哪个端口来访问。

c.NotebookApp.ip = '*'
c.NotebookApp.password = u'sha1:9c252a7bae90:23bf013a345e05be0b74a2xxxxxx'
c.NotebookApp.open_browser = False
c.NotebookApp.port = 8080

$ /data/anaconda3/bin/jupyter notebook
[W 10:59:15.335 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[I 10:59:15.347 NotebookApp] Serving notebooks from local directory: /home/centos
[I 10:59:15.347 NotebookApp] 0 active kernels 
[I 10:59:15.347 NotebookApp] The Jupyter Notebook is running at: http://[all ip addresses on your system]:8080/
[I 10:59:15.347 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[I 10:59:27.350 NotebookApp] Creating new notebook in 
[I 10:59:34.830 NotebookApp] Kernel started: a8d139ed-3d72-4d05-b02b-448975ab0aaa
[I 11:01:35.119 NotebookApp] Saving file at /Untitled.ipynb

搞定了,可以从浏览器访问 Jupyter 了,上面我已经访问了,而且创建了一个Untitled.ipynb 在默认的/home/centos(我的默认启动Jupyter时的目录)下。

等等,还有问题。停止它就用 Control+C,如果开机自动启动呢?

$ sudo /data/anaconda3/bin/jupyter notebook --allow-root --generate-config
Writing default config to: /root/.jupyter/jupyter_notebook_config.py

root 用户创建配置文件,再去修改配置文件(和前面类似)。 要确保创建了 root 用户运行的配置文件,能够 vi 打开就是创建了。

$ sudo vi /etc/rc.local 

加入以下

cd /home/centos
/data/anaconda3/bin/jupyter notebook --allow-root

$ reboot

重启,打开你的 ip:8080,登录密码就是你用 python 时输入的那个。 end.


最后修改于 2017-09-04