Anaconda

来自夜航船
跳到导航 跳到搜索

周末在家里浏览 Python 的视频,发现了 Anaconda,意外的惊喜。

我记得早些年,我就下载过 ActiveSate 发布的 ActivePython 和 ActivePerl,虽然到现在也没有学会 Python 和 Perl 的编程,但是知道了这样一种开发或者说是商业模式。

ActiveSate 公司的发现似乎很好,到现在已经有:Perl Python Tcl Ruby Node.js Go Lua 的 Solutions,还有 Komodo,an IDE for Web and Mobile App Development,看起来是找到这些开发语言中的痛点。

ActivePython 的 商业版售价:$999,还是企业版和OEM版本。

当时在Windows下练习Hello World,的确是感觉Python的包管理很痛苦,经常在命令行苦等而无果,ActivePython 集成了大部分常用的包,文档也很完善,看一眼就不会再错过。

而发展到今天,集成更加丰富,虽然我不会再试用 ActivePython ,但是这些集成的工具,却是我们学习 Python 的重要线路图。

Ubuntu 平台安装教程:http://chenzixin.com/

Jupyter Notebook

注:我安装Anaconda时,用的是root帐号,普通帐号并没有升级至Python3,因此要用最新版本的Python库,要以 root 身份运行。

# jupyter notebook --allow-root

LaTeX

https://www.latex-project.org

# Markdown
$\int_0^{+\infty} x^2 dx$
$$f(a) = \frac{1}{2\pi i} \oint\frac{f(z)}{z-a}dz$$

Matplotlib

%matplotlib inline

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(20)
y = x**2

plt.plot(x, y)

执行效果:

Matplotlib-Math

参考教程:Jupyter Notebook 快速入门

Ctrl + C 两次,退出。

应用笔记

启动和关闭

$ vim .jupyter/jupyter_notebook_config.py
$ ps aux | grep jupyter
$ lsof -i :2018 #1024

# 在Linux下,默认端口1024下的程序是要在root下才能使用的,在其他用户下,如果尝试使用将会报错

$ nohup jupyter notebook >~/log/jupyter.log 2>&1&
[2]  13638

nignx 代理

Notebook 和 nginx 绑定失败,目前的配置文件:

server {
    listen       80;
    server_name  ivy.christen.cn;

    location / {
        root   tree;
        index  tree# index.html index.htm;
        proxy_pass http://127.0.0.1:8888/;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_redirect off;
        }
}
  • terminals 无法打开
  • Kernel starting, please wait...
  • nbextensions/widgets/notebook/js/extension.js 404 独立运行时,也有这个错误

404 解决:

404 GET /nbextensions/widgets/notebook/js/extension.js?v=20180409160013 (111.202.222.130) 18.49ms referer=http://christen.cn:8888/notebooks/BeginningPython-Copy1.ipynb

$ jupyter nbextension enable --py widgetsnbextension
Enabling notebook extension jupyter-js-widgets/extension...
- Validating: OK

以下都是网上的成功配置,但是在我的服务器无效:

解决 Rename 故障

NoteBook rename Error: 400 Bad Request

延伸:RESTful, 说说 HTTP 的 patch method

PATCH http://christen.cn:8888/api/contents/SafariTimes.ipynb HTTP/1.1
Host: christen.cn:8888
Proxy-Connection: keep-alive
Content-Length: 27
Accept: application/json, text/javascript, */*; q=0.01
Origin: http://christen.cn:8888
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36
Content-Type: application/json
Referer: http://christen.cn:8888/notebooks/SafariTimes.ipynb
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9,en;q=0.8

Switch to GZ Proxy: 200 OK

Response:

{"kernel": {"id": "2b7801d7-82db-40d4-a5aa-a1d4384aa385", "name": "python3"}, "name": "", "notebook": {"path": "SafariTime.ipynb", "name": ""}, "path": "SafariTime.ipynb", "type": "notebook", "id": "ce58e6c1-7fdd-4639-bf5a-6016faf23770"}

双 Kernel 运行

# which python
/opt/anaconda/bin/python

$ /opt/anaconda/bin/python -m ipykernel install --user
Installed kernelspec python3 in /home/christen/.local/share/jupyter/kernels/python3

支持 Scala

https://github.com/jupyter/jupyter/wiki/Jupyter-kernels

Jupyter Scala is a Scala kernel for Jupyter. It aims at being a versatile and easily extensible alternative to other Scala kernels or notebook UIs, building on both Jupyter and Ammonite.

https://github.com/jupyter-scala/jupyter-scala Done

Run jupyter console with this kernel with

$ jupyter console --kernel scala

Use this kernel from Jupyter notebook, running

$ jupyter notebook

and selecting the "Scala" kernel.

$ jupyter kernelspec list
Available kernels:
  python2    /usr/local/lib/python2.7/dist-packages/ipykernel/resources
  python3    /home/christen/.local/share/jupyter/kernels/python3
  scala      /home/christen/.local/share/jupyter/kernels/scala

Perfect!

Packages

[/root/anaconda3] >>> /opt/anaconda
PREFIX=/opt/anaconda
installing: python-3.6.4-hc3d631a_1 ...
Python 3.6.4 :: Anaconda, Inc.
installing: ca-certificates-2017.08.26-h1d4fec5_0 ...
installing: conda-env-2.6.0-h36134e3_1 ...
installing: intel-openmp-2018.0.0-hc7b2577_8 ...
installing: libgcc-ng-7.2.0-h7cc24e2_2 ...
installing: libgfortran-ng-7.2.0-h9f7466a_2 ...
installing: libstdcxx-ng-7.2.0-h7a57d05_2 ...
installing: bzip2-1.0.6-h9a117a8_4 ...
installing: expat-2.2.5-he0dffb1_0 ...
installing: gmp-6.1.2-h6c8ec71_1 ...
installing: graphite2-1.3.10-hf63cedd_1 ...
installing: icu-58.2-h9c2bf20_1 ...
installing: jbig-2.1-hdba287a_0 ...
installing: jpeg-9b-h024ee3a_2 ...
installing: libffi-3.2.1-hd88cf55_4 ...
installing: libsodium-1.0.15-hf101ebd_0 ...
installing: libtool-2.4.6-h544aabb_3 ...
installing: libxcb-1.12-hcd93eb1_4 ...
installing: lzo-2.10-h49e0be7_2 ...
installing: mkl-2018.0.1-h19d6760_4 ...
installing: ncurses-6.0-h9df7e31_2 ...
installing: openssl-1.0.2n-hb7f436b_0 ...
installing: patchelf-0.9-hf79760b_2 ...
installing: pcre-8.41-hc27e229_1 ...
installing: pixman-0.34.0-hceecf20_3 ...
installing: tk-8.6.7-hc745277_3 ...
installing: unixodbc-2.3.4-hc36303a_1 ...
installing: xz-5.2.3-h55aa19d_2 ...
installing: yaml-0.1.7-had09818_2 ...
installing: zlib-1.2.11-ha838bed_2 ...
installing: glib-2.53.6-h5d9569c_2 ...
installing: hdf5-1.10.1-h9caa474_1 ...
installing: libedit-3.1-heed3624_0 ...
installing: libpng-1.6.34-hb9fc6fc_0 ...
installing: libssh2-1.8.0-h9cfc8f7_4 ...
installing: libtiff-4.0.9-h28f6b97_0 ...
installing: libxml2-2.9.7-h26e45fe_0 ...
installing: mpfr-3.1.5-h11a74b3_2 ...
installing: pandoc-1.19.2.1-hea2e7c5_1 ...
installing: readline-7.0-ha6073c6_4 ...
installing: zeromq-4.2.2-hbedb6e5_2 ...
installing: dbus-1.12.2-hc3f9b76_1 ...
installing: freetype-2.8-hab7d2ae_1 ...
installing: gstreamer-1.12.4-hb53b477_0 ...
installing: libcurl-7.58.0-h1ad7b7a_0 ...
installing: libxslt-1.1.32-h1312cb7_0 ...
installing: mpc-1.0.3-hec55b23_5 ...
installing: sqlite-3.22.0-h1bed415_0 ...
installing: curl-7.58.0-h84994c4_0 ...
installing: fontconfig-2.12.4-h88586e7_1 ...
installing: gst-plugins-base-1.12.4-h33fb286_0 ...
installing: alabaster-0.7.10-py36h306e16b_0 ...
installing: asn1crypto-0.24.0-py36_0 ...
installing: attrs-17.4.0-py36_0 ...
installing: backports-1.0-py36hfa02d7e_1 ...
installing: beautifulsoup4-4.6.0-py36h49b8c8c_1 ...
installing: bitarray-0.8.1-py36h14c3975_1 ...
installing: boto-2.48.0-py36h6e4cd66_1 ...
installing: cairo-1.14.12-h77bcde2_0 ...
installing: certifi-2018.1.18-py36_0 ...
installing: chardet-3.0.4-py36h0f667ec_1 ...
installing: click-6.7-py36h5253387_0 ...
installing: cloudpickle-0.5.2-py36_1 ...
installing: colorama-0.3.9-py36h489cec4_0 ...
installing: contextlib2-0.5.5-py36h6c84a62_0 ...
installing: dask-core-0.16.1-py36_0 ...
installing: decorator-4.2.1-py36_0 ...
installing: docutils-0.14-py36hb0f60f5_0 ...
installing: entrypoints-0.2.3-py36h1aec115_2 ...
installing: et_xmlfile-1.0.1-py36hd6bccc3_0 ...
installing: fastcache-1.0.2-py36h14c3975_2 ...
installing: filelock-2.0.13-py36h646ffb5_0 ...
installing: glob2-0.6-py36he249c77_0 ...
installing: gmpy2-2.0.8-py36hc8893dd_2 ...
installing: greenlet-0.4.12-py36h2d503a6_0 ...
installing: heapdict-1.0.0-py36_2 ...
installing: idna-2.6-py36h82fb2a8_1 ...
installing: imagesize-0.7.1-py36h52d8127_0 ...
installing: ipython_genutils-0.2.0-py36hb52b0d5_0 ...
installing: itsdangerous-0.24-py36h93cc618_1 ...
installing: jdcal-1.3-py36h4c697fb_0 ...
installing: lazy-object-proxy-1.3.1-py36h10fcdad_0 ...
installing: llvmlite-0.21.0-py36ha241eea_0 ...
installing: locket-0.2.0-py36h787c0ad_1 ...
installing: lxml-4.1.1-py36hf71bdeb_1 ...
installing: markupsafe-1.0-py36hd9260cd_1 ...
installing: mccabe-0.6.1-py36h5ad9710_1 ...
installing: mistune-0.8.3-py36_0 ...
installing: mkl-service-1.1.2-py36h17a0993_4 ...
installing: mpmath-1.0.0-py36hfeacd6b_2 ...
installing: msgpack-python-0.5.1-py36h6bb024c_0 ...
installing: multipledispatch-0.4.9-py36h41da3fb_0 ...
installing: numpy-1.14.0-py36h3dfced4_1 ...
installing: olefile-0.45.1-py36_0 ...
installing: pandocfilters-1.4.2-py36ha6701b7_1 ...
installing: parso-0.1.1-py36h35f843b_0 ...
installing: path.py-10.5-py36h55ceabb_0 ...
installing: pep8-1.7.1-py36_0 ...
installing: pickleshare-0.7.4-py36h63277f8_0 ...
installing: pkginfo-1.4.1-py36h215d178_1 ...
installing: pluggy-0.6.0-py36hb689045_0 ...
installing: ply-3.10-py36hed35086_0 ...
installing: psutil-5.4.3-py36h14c3975_0 ...
installing: ptyprocess-0.5.2-py36h69acd42_0 ...
installing: py-1.5.2-py36h29bf505_0 ...
installing: pycodestyle-2.3.1-py36hf609f19_0 ...
installing: pycosat-0.6.3-py36h0a5515d_0 ...
installing: pycparser-2.18-py36hf9f622e_1 ...
installing: pycrypto-2.6.1-py36h14c3975_7 ...
installing: pycurl-7.43.0.1-py36hb7f436b_0 ...
installing: pyodbc-4.0.22-py36hf484d3e_0 ...
installing: pyparsing-2.2.0-py36hee85983_1 ...
installing: pysocks-1.6.7-py36hd97a5b1_1 ...
installing: pytz-2017.3-py36h63b9c63_0 ...
installing: pyyaml-3.12-py36hafb9ca4_1 ...
installing: pyzmq-16.0.3-py36he2533c7_0 ...
installing: qt-5.6.2-h974d657_12 ...
installing: qtpy-1.3.1-py36h3691cc8_0 ...
installing: rope-0.10.7-py36h147e2ec_0 ...
installing: ruamel_yaml-0.15.35-py36h14c3975_1 ...
installing: send2trash-1.4.2-py36_0 ...
installing: simplegeneric-0.8.1-py36_2 ...
installing: sip-4.18.1-py36h51ed4ed_2 ...
installing: six-1.11.0-py36h372c433_1 ...
installing: snowballstemmer-1.2.1-py36h6febd40_0 ...
installing: sortedcontainers-1.5.9-py36_0 ...
installing: sphinxcontrib-1.0-py36h6d0f590_1 ...
installing: sqlalchemy-1.2.1-py36h14c3975_0 ...
installing: tblib-1.3.2-py36h34cf8b6_0 ...
installing: testpath-0.3.1-py36h8cadb63_0 ...
installing: toolz-0.9.0-py36_0 ...
installing: tornado-4.5.3-py36_0 ...
installing: typing-3.6.2-py36h7da032a_0 ...
installing: unicodecsv-0.14.1-py36ha668878_0 ...
installing: wcwidth-0.1.7-py36hdf4376a_0 ...
installing: webencodings-0.5.1-py36h800622e_1 ...
installing: werkzeug-0.14.1-py36_0 ...
installing: wrapt-1.10.11-py36h28b7045_0 ...
installing: xlrd-1.1.0-py36h1db9f0c_1 ...
installing: xlsxwriter-1.0.2-py36h3de1aca_0 ...
installing: xlwt-1.3.0-py36h7b00a1f_0 ...
installing: babel-2.5.3-py36_0 ...
installing: backports.shutil_get_terminal_size-1.0.0-py36hfea85ff_2 ...
installing: bottleneck-1.2.1-py36haac1ea0_0 ...
installing: cffi-1.11.4-py36h9745a5d_0 ...
installing: conda-verify-2.0.0-py36h98955d8_0 ...
installing: cycler-0.10.0-py36h93f1223_0 ...
installing: cytoolz-0.9.0-py36h14c3975_0 ...
installing: h5py-2.7.1-py36h3585f63_0 ...
installing: harfbuzz-1.7.4-hc5b324e_0 ...
installing: html5lib-1.0.1-py36h2f9c1c0_0 ...
installing: jedi-0.11.1-py36_0 ...
installing: networkx-2.1-py36_0 ...
installing: nltk-3.2.5-py36h7532b22_0 ...
installing: numba-0.36.2-np114py36hc6662d5_0 ...
installing: numexpr-2.6.4-py36hc4a3f9a_0 ...
installing: openpyxl-2.4.10-py36_0 ...
installing: packaging-16.8-py36ha668100_1 ...
installing: partd-0.3.8-py36h36fd896_0 ...
installing: pathlib2-2.3.0-py36h49efa8e_0 ...
installing: pexpect-4.3.1-py36_0 ...
installing: pillow-5.0.0-py36h3deb7b8_0 ...
installing: pyqt-5.6.0-py36h0386399_5 ...
installing: python-dateutil-2.6.1-py36h88d3b88_1 ...
installing: pywavelets-0.5.2-py36he602eb0_0 ...
installing: qtawesome-0.4.4-py36h609ed8c_0 ...
installing: scipy-1.0.0-py36hbf646e7_0 ...
installing: setuptools-38.4.0-py36_0 ...
installing: singledispatch-3.4.0.3-py36h7a266c3_0 ...
installing: sortedcollections-0.5.3-py36h3c761f9_0 ...
installing: sphinxcontrib-websupport-1.0.1-py36hb5cb234_1 ...
installing: sympy-1.1.1-py36hc6d1c1c_0 ...
installing: terminado-0.8.1-py36_1 ...
installing: traitlets-4.3.2-py36h674d592_0 ...
installing: zict-0.1.3-py36h3a3bf81_0 ...
installing: astroid-1.6.1-py36_0 ...
installing: bleach-2.1.2-py36_0 ...
installing: clyent-1.2.2-py36h7e57e65_1 ...
installing: cryptography-2.1.4-py36hd09be54_0 ...
installing: cython-0.27.3-py36h1860423_0 ...
installing: datashape-0.5.4-py36h3ad6b5c_0 ...
installing: distributed-1.20.2-py36_0 ...
installing: get_terminal_size-1.0.0-haa9412d_0 ...
installing: gevent-1.2.2-py36h2fe25dc_0 ...
installing: imageio-2.2.0-py36he555465_0 ...
installing: isort-4.2.15-py36had401c0_0 ...
installing: jinja2-2.10-py36ha16c418_0 ...
installing: jsonschema-2.6.0-py36h006f8b5_0 ...
installing: jupyter_core-4.4.0-py36h7c827e3_0 ...
installing: matplotlib-2.1.2-py36h0e671d2_0 ...
installing: navigator-updater-0.1.0-py36h14770f7_0 ...
installing: nose-1.3.7-py36hcdf7029_2 ...
installing: pandas-0.22.0-py36hf484d3e_0 ...
installing: pango-1.41.0-hd475d92_0 ...
installing: patsy-0.5.0-py36_0 ...
installing: pyflakes-1.6.0-py36h7bd6a15_0 ...
installing: pygments-2.2.0-py36h0d3125c_0 ...
installing: pytables-3.4.2-py36h3b5282a_2 ...
installing: pytest-3.3.2-py36_0 ...
installing: scikit-learn-0.19.1-py36h7aa7ec6_0 ...
installing: wheel-0.30.0-py36hfd4bba0_1 ...
installing: astropy-2.0.3-py36h14c3975_0 ...
installing: bkcharts-0.2-py36h735825a_0 ...
installing: bokeh-0.12.13-py36h2f9c1c0_0 ...
installing: flask-0.12.2-py36hb24657c_0 ...
installing: jupyter_client-5.2.2-py36_0 ...
installing: nbformat-4.4.0-py36h31c9010_0 ...
installing: pip-9.0.1-py36h6c6f9ce_4 ...
installing: prompt_toolkit-1.0.15-py36h17d85b1_0 ...
installing: pylint-1.8.2-py36_0 ...
installing: pyopenssl-17.5.0-py36h20ba746_0 ...
installing: statsmodels-0.8.0-py36h8533d0b_0 ...
installing: dask-0.16.1-py36_0 ...
installing: flask-cors-3.0.3-py36h2d857d3_0 ...
installing: ipython-6.2.1-py36h88c514a_1 ...
installing: nbconvert-5.3.1-py36hb41ffb7_0 ...
installing: seaborn-0.8.1-py36hfad7ec4_0 ...
installing: urllib3-1.22-py36hbe7ace6_0 ...
installing: ipykernel-4.8.0-py36_0 ...
installing: odo-0.5.1-py36h90ed295_0 ...
installing: requests-2.18.4-py36he2e5f8d_1 ...
installing: scikit-image-0.13.1-py36h14c3975_1 ...
installing: anaconda-client-1.6.9-py36_0 ...
installing: blaze-0.11.3-py36h4e06776_0 ...
installing: jupyter_console-5.2.0-py36he59e554_1 ...
installing: notebook-5.4.0-py36_0 ...
installing: qtconsole-4.3.1-py36h8f73b5b_0 ...
installing: sphinx-1.6.6-py36_0 ...
installing: anaconda-project-0.8.2-py36h44fb852_0 ...
installing: jupyterlab_launcher-0.10.2-py36_0 ...
installing: numpydoc-0.7.0-py36h18f165f_0 ...
installing: widgetsnbextension-3.1.0-py36_0 ...
installing: anaconda-navigator-1.7.0-py36_0 ...
installing: ipywidgets-7.1.1-py36_0 ...
installing: jupyterlab-0.31.5-py36_0 ...
installing: spyder-3.2.6-py36_0 ...
installing: _ipyw_jlab_nb_ext_conf-0.1.0-py36he11e457_0 ...
installing: jupyter-1.0.0-py36_4 ...
installing: anaconda-5.1.0-py36_2 ...
installing: conda-4.4.10-py36_0 ...
installing: conda-build-3.4.1-py36_0 ...
installation finished.