ipython notebook [jupyter] 使用

  ps:我一直在用爲知做筆記,我就在想如果有一個web界面的vim+跨平臺+即時運行結果的編輯器[還要什麼女朋友啊~j_0063.gif]

  jupyter筆記本是一個Web應用程序,允許你創建和共享代碼,方程,可視化和說明性文本文檔。用途包括:數據清洗和轉換,數值模擬,統計建模,機器學習等。

一、安裝jupyter

 1、本機環境 [看一下效果,哈哈~] wKioL1ZG87HCdSbZAAByLYKT8RI390.png

2、安裝過程

  注:我剛開始安裝的時候,怕被坑了,找了N多文檔,結果都就在安裝過程中出現各種問題,有解決依賴,無法保存的,無法補全的,不能用別名的。。。我以爲這樣就可以搞了,but 我竟然成功了,安裝過程在一片祥和的氛圍下最絡達成。

  提示:安裝前安裝開發包組Development tools,升級系統python版本,官方要求python2.6或3.2,但是jupyter 要Python 2.7 or >= 3.3,ipython當然是最新版本的,剩下的就是安裝了,一條命令搞定

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
yum instal -y python-pip  #如果沒有pip的話
#pip install virtualenv -y
[[email protected] python_object] # virtualenv --no-site-package ipython_notebook
New python executable  in  ipython_notebook /bin/python
Installing setuptools, pip, wheel... done .
[[email protected] python_object] # ls
Exect_number.py  firstfork.py  ipython_notebook  Prodicer.py    virtual_DJ
[[email protected] python_object] # source ipython_notebook/bin/activate
(ipython_notebook)[[email protected] python_object]
(ipython_notebook)[[email protected] python_object] # pip install jupyter
Collecting jupyter
/workspace/python_object/ipython_notebook/lib/python2 .7 /site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_ .py:90: InsecurePlatformWarning: A  true  SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For  more  information, see https: //urllib3 .readthedocs.org /en/latest/security .html #insecureplatformwarning.
   InsecurePlatformWarning
   Downloading jupyter-1.0.0-py2.py3-none-any.whl
Collecting notebook (from jupyter)
   Downloading notebook-4.0.6-py2.py3-none-any.whl (5.6MB)
     100% |████████████████████████████████| 5.6MB 57kB /s 
Collecting ipywidgets (from jupyter)
   Downloading ipywidgets-4.1.1-py2.py3-none-any.whl (117kB)
     100% |████████████████████████████████| 118kB 1.2MB /s 
Collecting nbconvert (from jupyter)
   Downloading nbconvert-4.1.0-py2.py3-none-any.whl (281kB)
     100% |████████████████████████████████| 282kB 735kB /s 
Collecting ipykernel (from jupyter)
   Downloading ipykernel-4.1.1-py2.py3-none-any.whl (90kB)
     100% |████████████████████████████████| 94kB 1.5MB /s 
Collecting jupyter-console (from jupyter)
   Downloading jupyter_console-4.0.3-py2.py3-none-any.whl
Collecting qtconsole (from jupyter)
   Downloading qtconsole-4.1.0-py2.py3-none-any.whl (98kB)
     100% |████████████████████████████████| 102kB 1.5MB /s 
Collecting traitlets (from notebook->jupyter)
   Using cached traitlets-4.0.0-py2.py3-none-any.whl
Collecting tornado>=4 (from notebook->jupyter)
   Downloading tornado-4.3. tar .gz (450kB)
     100% |████████████████████████████████| 454kB 313kB /s 
Collecting jupyter-client (from notebook->jupyter)
   Downloading jupyter_client-4.1.1-py2.py3-none-any.whl (70kB)
     100% |████████████████████████████████| 73kB 1.7MB /s 
Collecting nbformat (from notebook->jupyter)
   Downloading nbformat-4.0.1-py2.py3-none-any.whl (138kB)
     100% |████████████████████████████████| 139kB 1.3MB /s 
Collecting jupyter-core (from notebook->jupyter)
   Downloading jupyter_core-4.0.6-py2.py3-none-any.whl (74kB)
     100% |████████████████████████████████| 77kB 1.4MB /s 
Collecting jinja2 (from notebook->jupyter)
   Downloading Jinja2-2.8-py2.py3-none-any.whl (263kB)
     100% |████████████████████████████████| 266kB 222kB /s 
Collecting terminado>=0.3.3 (from notebook->jupyter)
   Downloading terminado-0.5. tar .gz
Collecting ipython-genutils (from notebook->jupyter)
   Using cached ipython_genutils-0.1.0-py2.py3-none-any.whl
Collecting ipython>=4.0.0dev0 (from ipywidgets->jupyter)
   Using cached ipython-4.0.0-py2-none-any.whl
Collecting pygments (from nbconvert->jupyter)
   Downloading Pygments-2.0.2-py2-none-any.whl (672kB)
     100% |████████████████████████████████| 675kB 434kB /s 
Collecting mistune!=0.6 (from nbconvert->jupyter)
   Downloading mistune-0.7.1-py2.py3-none-any.whl
Collecting decorator (from traitlets->notebook->jupyter)
   Downloading decorator-4.0.4-py2.py3-none-any.whl
Collecting backports.ssl-match- hostname  (from tornado>=4->notebook->jupyter)
   Downloading backports.ssl_match_hostname-3.4.0.2. tar .gz
Collecting singledispatch (from tornado>=4->notebook->jupyter)
   Downloading singledispatch-3.4.0.3-py2.py3-none-any.whl
Collecting certifi (from tornado>=4->notebook->jupyter)
   Downloading certifi-2015.9.6.2-py2.py3-none-any.whl (371kB)
     100% |████████████████████████████████| 372kB 797kB /s 
Collecting backports-abc>=0.4 (from tornado>=4->notebook->jupyter)
   Downloading backports_abc-0.4-py2.py3-none-any.whl
Collecting pyzmq>=13 (from jupyter-client->notebook->jupyter)
   Downloading pyzmq-15.0.0. tar .gz (1.1MB)
     100% |████████████████████████████████| 1.1MB 310kB /s 
Collecting jsonschema!=2.5.0,>=2.0 (from nbformat->notebook->jupyter)
   Downloading jsonschema-2.5.1-py2.py3-none-any.whl
Collecting MarkupSafe (from jinja2->notebook->jupyter)
   Downloading MarkupSafe-0.23. tar .gz
Collecting ptyprocess (from terminado>=0.3.3->notebook->jupyter)
   Using cached ptyprocess-0.5. tar .gz
Collecting simplegeneric>0.8 (from ipython>=4.0.0dev0->ipywidgets->jupyter)
   Using cached simplegeneric-0.8.1.zip
Collecting pexpect (from ipython>=4.0.0dev0->ipywidgets->jupyter)
   Using cached pexpect-4.0.1. tar .gz
Collecting pickleshare (from ipython>=4.0.0dev0->ipywidgets->jupyter)
   Using cached pickleshare-0.5. tar .gz
Collecting six (from singledispatch->tornado>=4->notebook->jupyter)
   Using cached six-1.10.0-py2.py3-none-any.whl
Collecting functools32 (from jsonschema!=2.5.0,>=2.0->nbformat->notebook->jupyter)
   Downloading functools32-3.2.3-2. tar .gz
Collecting path.py (from pickleshare->ipython>=4.0.0dev0->ipywidgets->jupyter)
   Using cached path.py-8.1.2-py2.py3-none-any.whl
Building wheels  for  collected packages: tornado, terminado, backports.ssl-match- hostname , pyzmq, MarkupSafe, ptyprocess, simplegeneric, pexpect, pickleshare, functools32
   Running setup.py bdist_wheel  for  tornado
   Stored  in  directory:  /root/ .cache /pip/wheels/2d/e6/19/1a61a89abb78cc3e1761a5844eaa1fdc86fd41b38353df5967
   Running setup.py bdist_wheel  for  terminado
   Stored  in  directory:  /root/ .cache /pip/wheels/f9/7c/62/fe686f920ed9fbc013e631a5415ec3162602b31e762595e3fe
   Running setup.py bdist_wheel  for  backports.ssl-match- hostname
   Stored  in  directory:  /root/ .cache /pip/wheels/81/3d/36/f3c726a42caed585046d710e0e450bda1075c61c1c43443831
   Running setup.py bdist_wheel  for  pyzmq
   Stored  in  directory:  /root/ .cache /pip/wheels/3a/7a/27/93f017cb86670a08e6114a95c05885bb4dda1f81830ff4306c
   Running setup.py bdist_wheel  for  MarkupSafe
   Stored  in  directory:  /root/ .cache /pip/wheels/94/a7/79/f79a998b64c1281cb99fa9bbd33cfc9b8b5775f438218d17a7
   Running setup.py bdist_wheel  for  ptyprocess
   Stored  in  directory:  /root/ .cache /pip/wheels/8f/0b/d5/45ebc79539db587c173a63b42572328136bdb098210767fb80
   Running setup.py bdist_wheel  for  simplegeneric
   Stored  in  directory:  /root/ .cache /pip/wheels/51/3c/13/2b621669f3ba74b01380aefcc0af0f643bb42360e7248496ed
   Running setup.py bdist_wheel  for  pexpect
   Stored  in  directory:  /root/ .cache /pip/wheels/ea/5b/53/4b65a279e1390ae81febe74f660ce01ef4655c9c1ec9acd9bf
   Running setup.py bdist_wheel  for  pickleshare
   Stored  in  directory:  /root/ .cache /pip/wheels/99/3e/8b/7d87bf47f2c2d437fcb9a913cd5c4b393b7132c508633e3eef
   Running setup.py bdist_wheel  for  functools32
   Stored  in  directory:  /root/ .cache /pip/wheels/38/c6/c7/ee17acd621120c302e25c2fa8b3a8b235d5d1137c6ab4c9728
Successfully built tornado terminado backports.ssl-match- hostname  pyzmq MarkupSafe ptyprocess simplegeneric pexpect pickleshare functools32
Installing collected packages: decorator, ipython-genutils, traitlets, backports.ssl-match- hostname , six, singledispatch, certifi, backports-abc, tornado, jupyter-core, pyzmq, jupyter-client, functools32, jsonschema, nbformat, MarkupSafe, jinja2, simplegeneric, ptyprocess, pexpect, path.py, pickleshare, ipython, ipykernel, terminado, pygments, mistune, nbconvert, notebook, ipywidgets, jupyter-console, qtconsole, jupyter
Successfully installed MarkupSafe-0.23 backports-abc-0.4 backports.ssl-match- hostname -3.4.0.2 certifi-2015.9.6.2 decorator-4.0.4 functools32-3.2.3.post2 ipykernel-4.1.1 ipython-4.0.0 ipython-genutils-0.1.0 ipywidgets-4.1.1 jinja2-2.8 jsonschema-2.5.1 jupyter-1.0.0 jupyter-client-4.1.1 jupyter-console-4.0.3 jupyter-core-4.0.6 mistune-0.7.1 nbconvert-4.1.0 nbformat-4.0.1 notebook-4.0.6 path.py-8.1.2 pexpect-4.0.1 pickleshare-0.5 ptyprocess-0.5 pygments-2.0.2 pyzmq-15.0.0 qtconsole-4.1.0 simplegeneric-0.8.1 singledispatch-3.4.0.3 six-1.10.0 terminado-0.5 tornado-4.3 traitlets-4.0.0

到此jupyter己經安裝完成了,看到這麼多的依賴,我對那些一步步排錯手並安裝成功,只能說我不如他們!

二、jupyter的使用

 1、jupyter 幫助

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
(ipython_notebook)[[email protected] python_object] # jupyter -h
usage: jupyter [-h] [--version] [--config- dir ] [--data- dir ] [--runtime- dir ]
                [--paths] [--json]
                [subcommand]
 
Jupyter: Interactive Computing
 
positional arguments:
   subcommand     the subcommand to launch
 
optional arguments:
   -h, --help     show this help message and  exit
   --version      show the jupyter  command 's version and  exit
   --config- dir    show Jupyter config  dir
   --data- dir      show Jupyter data  dir
   --runtime- dir   show Jupyter runtime  dir
   --paths        show all Jupyter paths. Add --json  for  machine-readable
                  format .
   --json         output paths as machine-readable json
 
Available subcommands: console kernelspec migrate nbconvert nbextension
notebook qtconsole trust

 2、啓動jupyter notebook

   啓動jupyter notebook後默認監聽於本地8888,如果想外部訪問也很簡單 

1
jupyter notebook --ip=x.x.x.x

這樣就可從web界面訪問了

 3、jupyter notebook web界面的使用

 wKiom1ZG_HPwq8YhAAB3sWrziRU686.png

這些目錄都在安裝所使用的用戶的.ipython的目錄下。

如果你不想使用默認的配置參數,可以直接寫配置文件,啓動服務時引用配置文件。

我們重點說一下python2[右邊最後一個功能],其它的一看就知道是什麼意思了【2333.。】

打開後與前面的截圖是一樣的,這可以看作ipython的web界面,但它的功能不止於此,你可以把它當成編輯器,notebook,如果單一的使用ipython或是vim感覺總是缺點什麼,但jupyter notebook就將兩者結合的很好,當然還可能安裝許多額外的擴展更好的支持你所需要的功能。

如果你不知道有那些快捷鍵可以點help-->Keyboard shortcuts查看支持的快捷鍵,還可以看幫助引導,分分鐘教會你使用[我知道還是上圖更有說服力,但太多了,就不操作了,當你安裝成功自己找吧]

說的再多也不及你自己安裝完成後體驗一下。[我在網上見過一個大牛用jupyter寫項目。。] 










本文轉自 jinlinger 51CTO博客,原文鏈接:http://blog.51cto.com/essun/1712773,如需轉載請自行聯繫原作者