1、Jupyter简介
Jupyter Notebooks 是一款开源的网络应用,我们可以将其用于创建和共享代码与文档。
其提供了一个环境,你无需离开这个环境,就可以在其中编写你的代码、运行代码、查看输出、可视化数据并查看结果。因此,这是一款可执行端到端的数据科学工作流程的便捷工具,其中包括数据清理、统计建模、构建和训练机器学习模型、可视化数据等等。
Jupyter Notebooks 是数据科学/机器学习社区内一款非常流行的工具。Analytics Vidhya 的 Pranav Dar 近日发表了一篇上手使用 Jupyter Notebooks 的指南,从安装到基本功能进行了简洁清晰的介绍。
2、Jupyter搭建
安装Python3
brew install python
在mac book 终端中输入如下命令:
pip3 install --user jupyter
安装过程中报错:
问题1:
matplotlib 1.3.1 requires nose, which is not installed.
解决方法
pip3 install --user matplotlib
问题2:
Cannot uninstall 'six'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
解决方法
sudo pip3 install six --upgrade --ignore-installed six
安装成功
The directory '/Users/vesus/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/vesus/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting jupyter
Downloading https://files.pythonhosted.org/packages/83/df/0f5dd132200728a86190397e1ea87cd76244e42d39ec5e88efd25b2abd7e/jupyter-1.0.0-py2.py3-none-any.whl
Collecting jupyter-console (from jupyter)
Downloading https://files.pythonhosted.org/packages/77/82/6469cd7fccf7958cbe5dce2e623f1e3c5e27f1bb1ad36d90519bc2d5d370/jupyter_console-5.2.0-py2.py3-none-any.whl
Collecting ipykernel (from jupyter)
Downloading https://files.pythonhosted.org/packages/00/47/764e4fa1b1b89598426b8d79b1c4fbe8042432621b0f8e1991aeb3c24806/ipykernel-4.10.0-py2-none-any.whl (110kB)
100% |████████████████████████████████| 112kB 299kB/s
Collecting notebook (from jupyter)
Downloading https://files.pythonhosted.org/packages/f6/36/89ebfffc9dd8c8dbd81c1ffb53e3d4233ee666414c143959477cb07cc5f5/notebook-5.7.8-py2.py3-none-any.whl (9.0MB)
100% |████████████████████████████████| 9.0MB 3.5MB/s
Collecting nbconvert (from jupyter)
Downloading https://files.pythonhosted.org/packages/35/e7/f46c9d65f149271e47fca6ab084ef5c6e4cb1870f4c5cce6690feac55231/nbconvert-5.5.0-py2.py3-none-any.whl (447kB)
100% |████████████████████████████████| 450kB 12.5MB/s
Collecting qtconsole (from jupyter)
Downloading https://files.pythonhosted.org/packages/79/0b/efb5a694b6922bb85c35e4f1db6197daae23c764dd384023fc9517d79e26/qtconsole-4.5.1-py2.py3-none-any.whl (118kB)
100% |████████████████████████████████| 122kB 9.7MB/s
Collecting ipywidgets (from jupyter)
Downloading https://files.pythonhosted.org/packages/30/9a/a008c7b1183fac9e52066d80a379b3c64eab535bd9d86cdc29a0b766fd82/ipywidgets-7.4.2-py2.py3-none-any.whl (111kB)
100% |████████████████████████████████| 112kB 8.4MB/s
Collecting jupyter-client (from jupyter-console->jupyter)
Downloading https://files.pythonhosted.org/packages/3b/c3/3043fe9ffd140d03c9d091a056794ccdc427c56ec19b8eea74f9ea0a498f/jupyter_client-5.2.4-py2.py3-none-any.whl (89kB)
100% |████████████████████████████████| 92kB 8.9MB/s
Collecting ipython (from jupyter-console->jupyter)
Downloading https://files.pythonhosted.org/packages/b0/88/d996ab8be22cea1eaa18baee3678a11265e18cf09974728d683c51102148/ipython-5.8.0-py2-none-any.whl (760kB)
100% |████████████████████████████████| 768kB 7.5MB/s
Collecting pygments (from jupyter-console->jupyter)
Downloading https://files.pythonhosted.org/packages/51/d2/181e37a5f0c883f0ca000d94e01a3c2bdc2178227ba5a80046004854459c/Pygments-2.4.1-py2.py3-none-any.whl (882kB)
100% |████████████████████████████████| 890kB 20.5MB/s
Collecting prompt-toolkit<2.0.0,>=1.0.0 (from jupyter-console->jupyter)
Downloading https://files.pythonhosted.org/packages/4e/4e/e5545e8bebf89790455b31112a0f886580c7b3624a05abec416efa5c3a08/prompt_toolkit-1.0.16-py2-none-any.whl (244kB)
100% |████████████████████████████████| 245kB 10.3MB/s
Requirement already satisfied: tornado>=4.0 in ./Library/Python/2.7/lib/python/site-packages (from ipykernel->jupyter) (5.1.1)
Requirement already satisfied: traitlets>=4.1.0 in /Library/Python/2.7/site-packages (from ipykernel->jupyter) (4.3.2)
Requirement already satisfied: jupyter-core>=4.4.0 in /Library/Python/2.7/site-packages (from notebook->jupyter) (4.4.0)
Requirement already satisfied: ipython-genutils in /Library/Python/2.7/site-packages (from notebook->jupyter) (0.2.0)
Collecting terminado>=0.8.1 (from notebook->jupyter)
Downloading https://files.pythonhosted.org/packages/a7/56/80ea7fa66565fa75ae21ce0c16bc90067530e5d15e48854afcc86585a391/terminado-0.8.2-py2.py3-none-any.whl
Collecting jinja2 (from notebook->jupyter)
Downloading https://files.pythonhosted.org/packages/1d/e7/fd8b501e7a6dfe492a433deb7b9d833d39ca74916fa8bc63dd1a4947a671/Jinja2-2.10.1-py2.py3-none-any.whl (124kB)
100% |████████████████████████████████| 133kB 10.5MB/s
Requirement already satisfied: ipaddress; python_version == "2.7" in /Library/Python/2.7/site-packages (from notebook->jupyter) (1.0.22)
Requirement already satisfied: pyzmq>=17 in /Library/Python/2.7/site-packages (from notebook->jupyter) (18.0.1)
Collecting nbformat (from notebook->jupyter)
Downloading https://files.pythonhosted.org/packages/da/27/9a654d2b6cc1eaa517d1c5a4405166c7f6d72f04f6e7eea41855fe808a46/nbformat-4.4.0-py2.py3-none-any.whl (155kB)
100% |████████████████████████████████| 163kB 9.8MB/s
Collecting Send2Trash (from notebook->jupyter)
Downloading https://files.pythonhosted.org/packages/13/2e/ea40de0304bb1dc4eb309de90aeec39871b9b7c4bd30f1a3cdcb3496f5c0/Send2Trash-1.5.0.tar.gz
Collecting prometheus-client (from notebook->jupyter)
Downloading https://files.pythonhosted.org/packages/4c/bd/b42db3ec90ffc6be805aad09c1cea4bb13a620d0cd4b21aaa44d13541d71/prometheus_client-0.6.0.tar.gz
Collecting mistune>=0.8.1 (from nbconvert->jupyter)
Downloading https://files.pythonhosted.org/packages/09/ec/4b43dae793655b7d8a25f76119624350b4d65eb663459eb9603d7f1f0345/mistune-0.8.4-py2.py3-none-any.whl
Collecting bleach (from nbconvert->jupyter)
Downloading https://files.pythonhosted.org/packages/ab/05/27e1466475e816d3001efb6e0a85a819be17411420494a1e602c36f8299d/bleach-3.1.0-py2.py3-none-any.whl (157kB)
100% |████████████████████████████████| 163kB 8.6MB/s
Collecting defusedxml (from nbconvert->jupyter)
Downloading https://files.pythonhosted.org/packages/06/74/9b387472866358ebc08732de3da6dc48e44b0aacd2ddaa5cb85ab7e986a2/defusedxml-0.6.0-py2.py3-none-any.whl
Collecting testpath (from nbconvert->jupyter)
Downloading https://files.pythonhosted.org/packages/be/a4/162f9ebb6489421fe46dcca2ae420369edfee4b563c668d93cb4605d12ba/testpath-0.4.2-py2.py3-none-any.whl (163kB)
100% |████████████████████████████████| 163kB 11.7MB/s
Collecting pandocfilters>=1.4.1 (from nbconvert->jupyter)
Downloading https://files.pythonhosted.org/packages/4c/ea/236e2584af67bb6df960832731a6e5325fd4441de001767da328c33368ce/pandocfilters-1.4.2.tar.gz
Collecting entrypoints>=0.2.2 (from nbconvert->jupyter)
Downloading https://files.pythonhosted.org/packages/ac/c6/44694103f8c221443ee6b0041f69e2740d89a25641e62fb4f2ee568f2f9c/entrypoints-0.3-py2.py3-none-any.whl
Collecting widgetsnbextension~=3.4.0 (from ipywidgets->jupyter)
Downloading https://files.pythonhosted.org/packages/8a/81/35789a3952afb48238289171728072d26d6e76649ddc8b3588657a2d78c1/widgetsnbextension-3.4.2-py2.py3-none-any.whl (2.2MB)
100% |████████████████████████████████| 2.2MB 5.2MB/s
Collecting python-dateutil>=2.1 (from jupyter-client->jupyter-console->jupyter)
Downloading https://files.pythonhosted.org/packages/41/17/c62faccbfbd163c7f57f3844689e3a78bae1f403648a6afb1d0866d87fbb/python_dateutil-2.8.0-py2.py3-none-any.whl (226kB)
100% |████████████████████████████████| 235kB 12.2MB/s
Requirement already satisfied: setuptools>=18.5 in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from ipython->jupyter-console->jupyter) (18.5)
Collecting simplegeneric>0.8 (from ipython->jupyter-console->jupyter)
Downloading https://files.pythonhosted.org/packages/3d/57/4d9c9e3ae9a255cd4e1106bb57e24056d3d0709fc01b2e3e345898e49d5b/simplegeneric-0.8.1.zip
Collecting backports.shutil-get-terminal-size; python_version == "2.7" (from ipython->jupyter-console->jupyter)
Downloading https://files.pythonhosted.org/packages/7d/cd/1750d6c35fe86d35f8562091737907f234b78fdffab42b29c72b1dd861f4/backports.shutil_get_terminal_size-1.0.0-py2.py3-none-any.whl
Collecting appnope; sys_platform == "darwin" (from ipython->jupyter-console->jupyter)
Downloading https://files.pythonhosted.org/packages/87/a9/7985e6a53402f294c8f0e8eff3151a83f1fb901fa92909bb3ff29b4d22af/appnope-0.1.0-py2.py3-none-any.whl
Collecting pexpect; sys_platform != "win32" (from ipython->jupyter-console->jupyter)
Downloading https://files.pythonhosted.org/packages/0e/3e/377007e3f36ec42f1b84ec322ee12141a9e10d808312e5738f52f80a232c/pexpect-4.7.0-py2.py3-none-any.whl (58kB)
100% |████████████████████████████████| 61kB 16.7MB/s
Collecting pickleshare (from ipython->jupyter-console->jupyter)
Downloading https://files.pythonhosted.org/packages/9a/41/220f49aaea88bc6fa6cba8d05ecf24676326156c23b991e80b3f2fc24c77/pickleshare-0.7.5-py2.py3-none-any.whl
Requirement already satisfied: decorator in /Library/Python/2.7/site-packages (from ipython->jupyter-console->jupyter) (4.4.0)
Collecting pathlib2; python_version == "2.7" or python_version == "3.3" (from ipython->jupyter-console->jupyter)
Downloading https://files.pythonhosted.org/packages/2a/46/c696dcf1c7aad917b39b875acdc5451975e3a9b4890dca8329983201c97a/pathlib2-2.3.3-py2.py3-none-any.whl
Collecting wcwidth (from prompt-toolkit<2.0.0,>=1.0.0->jupyter-console->jupyter)
Downloading https://files.pythonhosted.org/packages/7e/9f/526a6947247599b084ee5232e4f9190a38f398d7300d866af3ab571a5bfe/wcwidth-0.1.7-py2.py3-none-any.whl
Requirement already satisfied: six>=1.9.0 in /Library/Python/2.7/site-packages (from prompt-toolkit<2.0.0,>=1.0.0->jupyter-console->jupyter) (1.12.0)
Requirement already satisfied: futures in /Library/Python/2.7/site-packages (from tornado>=4.0->ipykernel->jupyter) (3.2.0)
Requirement already satisfied: singledispatch in ./Library/Python/2.7/lib/python/site-packages (from tornado>=4.0->ipykernel->jupyter) (3.4.0.3)
Requirement already satisfied: backports_abc>=0.4 in ./Library/Python/2.7/lib/python/site-packages (from tornado>=4.0->ipykernel->jupyter) (0.5)
Requirement already satisfied: enum34; python_version == "2.7" in /Library/Python/2.7/site-packages (from traitlets>=4.1.0->ipykernel->jupyter) (1.1.6)
Collecting ptyprocess; os_name != "nt" (from terminado>=0.8.1->notebook->jupyter)
Downloading https://files.pythonhosted.org/packages/d1/29/605c2cc68a9992d18dada28206eeada56ea4bd07a239669da41674648b6f/ptyprocess-0.6.0-py2.py3-none-any.whl
Collecting MarkupSafe>=0.23 (from jinja2->notebook->jupyter)
Downloading https://files.pythonhosted.org/packages/6d/d2/0ccd2c0e2cd93b35e765d9b3205cd6602e6b202b522fc7997531353715b3/MarkupSafe-1.1.1-cp27-cp27m-macosx_10_6_intel.whl
Collecting jsonschema!=2.5.0,>=2.4 (from nbformat->notebook->jupyter)
Downloading https://files.pythonhosted.org/packages/aa/69/df679dfbdd051568b53c38ec8152a3ab6bc533434fc7ed11ab034bf5e82f/jsonschema-3.0.1-py2.py3-none-any.whl (54kB)
100% |████████████████████████████████| 61kB 12.4MB/s
Collecting webencodings (from bleach->nbconvert->jupyter)
Downloading https://files.pythonhosted.org/packages/f4/24/2a3e3df732393fed8b3ebf2ec078f05546de641fe1b667ee316ec1dcf3b7/webencodings-0.5.1-py2.py3-none-any.whl
Collecting configparser>=3.5; python_version == "2.7" (from entrypoints>=0.2.2->nbconvert->jupyter)
Downloading https://files.pythonhosted.org/packages/ba/05/6c96328e92e625fc31445d24d75a2c92ef9ba34fc5b037fe69693c362a0d/configparser-3.7.4-py2.py3-none-any.whl
Collecting scandir; python_version < "3.5" (from pathlib2; python_version == "2.7" or python_version == "3.3"->ipython->jupyter-console->jupyter)
Downloading https://files.pythonhosted.org/packages/df/f5/9c052db7bd54d0cbf1bc0bb6554362bba1012d03e5888950a4f5c5dadc4e/scandir-1.10.0.tar.gz
Collecting attrs>=17.4.0 (from jsonschema!=2.5.0,>=2.4->nbformat->notebook->jupyter)
Downloading https://files.pythonhosted.org/packages/23/96/d828354fa2dbdf216eaa7b7de0db692f12c234f7ef888cc14980ef40d1d2/attrs-19.1.0-py2.py3-none-any.whl
Collecting functools32; python_version < "3" (from jsonschema!=2.5.0,>=2.4->nbformat->notebook->jupyter)
Downloading https://files.pythonhosted.org/packages/c5/60/6ac26ad05857c601308d8fb9e87fa36d0ebf889423f47c3502ef034365db/functools32-3.2.3-2.tar.gz
Collecting pyrsistent>=0.14.0 (from jsonschema!=2.5.0,>=2.4->nbformat->notebook->jupyter)
Downloading https://files.pythonhosted.org/packages/68/0b/f514e76b4e074386b60cfc6c8c2d75ca615b81e415417ccf3fac80ae0bf6/pyrsistent-0.15.2.tar.gz (106kB)
100% |████████████████████████████████| 112kB 14.6MB/s
Installing collected packages: python-dateutil, jupyter-client, simplegeneric, backports.shutil-get-terminal-size, pygments, appnope, ptyprocess, pexpect, scandir, pathlib2, pickleshare, wcwidth, prompt-toolkit, ipython, ipykernel, jupyter-console, terminado, MarkupSafe, jinja2, mistune, webencodings, bleach, attrs, functools32, pyrsistent, jsonschema, nbformat, defusedxml, testpath, pandocfilters, configparser, entrypoints, nbconvert, Send2Trash, prometheus-client, notebook, qtconsole, widgetsnbextension, ipywidgets, jupyter
The scripts jupyter-kernel, jupyter-kernelspec and jupyter-run are installed in '/Users/vesus/Library/Python/2.7/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Running setup.py install for simplegeneric ... done
The script pygmentize is installed in '/Users/vesus/Library/Python/2.7/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Running setup.py install for scandir ... done
The scripts iptest, iptest2, ipython and ipython2 are installed in '/Users/vesus/Library/Python/2.7/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
The script jupyter-console is installed in '/Users/vesus/Library/Python/2.7/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Running setup.py install for functools32 ... done
Running setup.py install for pyrsistent ... done
The script jsonschema is installed in '/Users/vesus/Library/Python/2.7/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
The script jupyter-trust is installed in '/Users/vesus/Library/Python/2.7/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Running setup.py install for pandocfilters ... done
The script jupyter-nbconvert is installed in '/Users/vesus/Library/Python/2.7/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Running setup.py install for Send2Trash ... done
Running setup.py install for prometheus-client ... done
The scripts jupyter-bundlerextension, jupyter-nbextension, jupyter-notebook and jupyter-serverextension are installed in '/Users/vesus/Library/Python/2.7/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed MarkupSafe-1.1.1 Send2Trash-1.5.0 appnope-0.1.0 attrs-19.1.0 backports.shutil-get-terminal-size-1.0.0 bleach-3.1.0 configparser-3.7.4 defusedxml-0.6.0 entrypoints-0.3 functools32-3.2.3.post2 ipykernel-4.10.0 ipython-5.8.0 ipywidgets-7.4.2 jinja2-2.10.1 jsonschema-3.0.1 jupyter-1.0.0 jupyter-client-5.2.4 jupyter-console-5.2.0 mistune-0.8.4 nbconvert-5.5.0 nbformat-4.4.0 notebook-5.7.8 pandocfilters-1.4.2 pathlib2-2.3.3 pexpect-4.7.0 pickleshare-0.7.5 prometheus-client-0.6.0 prompt-toolkit-1.0.16 ptyprocess-0.6.0 pygments-2.4.1 pyrsistent-0.15.2 python-dateutil-2.8.0 qtconsole-4.5.1 scandir-1.10.0 simplegeneric-0.8.1 terminado-0.8.2 testpath-0.4.2 wcwidth-0.1.7 webencodings-0.5.1 widgetsnbextension-3.4.2
3、Jupyter使用
添加环境变量
sudo vim ~/.bash_profile
export PATH=/Users/vesus/Library/Python/3.7/bin/:$PATH
环境变量生效
source ~/.bash_profile
在工作目录中运行:
jupyter notebook
启动后显示如图:
4、快捷键
Shift+Enter : 运行本单元,选中下个单元
Ctrl+Enter : 运行本单元
Alt+Enter : 运行本单元,在其下插入新单元
Y:单元转入代码状态
M:单元转入markdown状态
A :在上方插入新单元
B:在下方插入新单元
X:剪切选中的单元
Shift +V:在上方粘贴单元