Jupyter Notebook是一個交互式筆記本,支持運行40多種程式語言。Jupyter Notebook 的本質是一個 Web 應用程式,便於創建和共享文學化程序文檔,支持實時代碼,數學方程,可視化和 markdown。用途包括:數據清理和轉換,數值模擬,統計建模,機器學習等等。
二.安裝步驟環境:Linux
1. 使用pip安裝Jupyter(test_envs) [root@iZuf60a8w2ct7p4wqkf5c3Z tmp]# pip install jupyter
Looking in indexes: http://mirrors.cloud.aliyuncs.com/pypi/simple/
Collecting jupyter
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/83/df/0f5dd132200728a86190397e1ea87cd76244e42d39ec5e88efd25b2abd7e/jupyter-1.0.0-py2.py3-none-any.whl (2.7 kB)
Collecting ipywidgets
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/56/a0/dbcf5881bb2f51e8db678211907f16ea0a182b232c591a6d6f276985ca95/ipywidgets-7.5.1-py2.py3-none-any.whl (121 kB)
|████████████████████████████████| 121 kB 21.9 MB/s
Collecting jupyter-console
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/0a/89/742fa5a80b552ffcb6a8922712697c6e6828aee7b91ee4ae2b79f00f8401/jupyter_console-6.1.0-py2.py3-none-any.whl (21 kB)
Collecting notebook
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/b1/f1/0a67f09ef53a342403ffa66646ee39273e0ac79ffa5de5dbe2f3e28b5bdf/notebook-6.0.3-py3-none-any.whl (9.7 MB)
|████████████████████████████████| 9.7 MB 926 kB/s
Collecting qtconsole
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/61/9c/ee26b844381f0cf2ea24bd822e4a9ed2c7fd6d8cdeef63be459c62132f9b/qtconsole-4.7.4-py2.py3-none-any.whl (118 kB)
|████████████████████████████████| 118 kB 36.0 MB/s
Collecting ipykernel
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/61/18/f2350f0396fca562c22f880e25d668eaf6de129b6a56bf5b6786796a12e1/ipykernel-5.3.0-py3-none-any.whl (119 kB)
|████████████████████████████████| 119 kB 78.1 MB/s
Collecting nbconvert
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/79/6c/05a569e9f703d18aacb89b7ad6075b404e8a4afde2c26b73ca77bb644b14/nbconvert-5.6.1-py2.py3-none-any.whl (455 kB)
|████████████████████████████████| 455 kB 742 kB/s
Collecting widgetsnbextension~=3.5.0
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/6c/7b/7ac231c20d2d33c445eaacf8a433f4e22c60677eb9776c7c5262d7ddee2d/widgetsnbextension-3.5.1-py2.py3-none-any.whl (2.2 MB)
|████████████████████████████████| 2.2 MB 6.5 MB/s
Collecting nbformat>=4.2.0
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/4d/d1/b568bd35f95321f152f594b3647cd080e96d3347843ff2fa34dce871b8bf/nbformat-5.0.7-py3-none-any.whl (170 kB)
|████████████████████████████████| 170 kB 45.0 MB/s
Requirement already satisfied: ipython>=4.0.0; python_version >= "3.3" in /root/Envs/test_envs/lib/python3.6/site-packages (from ipywidgets->jupyter) (7.14.0)
Requirement already satisfied: traitlets>=4.3.1 in /root/Envs/test_envs/lib/python3.6/site-packages (from ipywidgets->jupyter) (4.3.3)
Requirement already satisfied: pygments in /root/Envs/test_envs/lib/python3.6/site-packages (from jupyter-console->jupyter) (2.6.1)
Collecting jupyter-client
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/34/0b/2ebddf775f558158ca8df23b35445fb15d4b1558a9e4a03bc7e75b13476e/jupyter_client-6.1.3-py3-none-any.whl (106 kB)
|████████████████████████████████| 106 kB 55.0 MB/s
Requirement already satisfied: prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0 in /root/Envs/test_envs/lib/python3.6/site-packages (from jupyter-console->jupyter) (3.0.5)
Requirement already satisfied: jinja2 in /root/Envs/test_envs/lib/python3.6/site-packages (from notebook->jupyter) (2.11.2)
Collecting terminado>=0.8.1
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/ff/96/1d9a2c23990aea8f8e0b5c3b6627d03196a73771a17a2d9860bbe9823ab6/terminado-0.8.3-py2.py3-none-any.whl (33 kB)
Requirement already satisfied: ipython-genutils in /root/Envs/test_envs/lib/python3.6/site-packages (from notebook->jupyter) (0.2.0)
Collecting jupyter-core>=4.6.1
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/63/0d/df2d17cdf389cea83e2efa9a4d32f7d527ba78667e0153a8e676e957b2f7/jupyter_core-4.6.3-py2.py3-none-any.whl (83 kB)
|████████████████████████████████| 83 kB 27.2 MB/s
Collecting Send2Trash
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/49/46/c3dc27481d1cc57b9385aff41c474ceb7714f7935b1247194adae45db714/Send2Trash-1.5.0-py3-none-any.whl (12 kB)
Collecting prometheus-client
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/3f/0e/554a265ffdc56e1494ef08e18f765b0cdec78797f510c58c45cf37abb4f4/prometheus_client-0.8.0-py2.py3-none-any.whl (53 kB)
|████████████████████████████████| 53 kB 42.9 MB/s
Collecting tornado>=5.0
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/95/84/119a46d494f008969bf0c775cb2c6b3579d3c4cc1bb1b41a022aa93ee242/tornado-6.0.4.tar.gz (496 kB)
|████████████████████████████████| 496 kB 57.1 MB/s
Collecting pyzmq>=17
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/c9/11/bb28199dd8f186a4053b7dd94a33abf0c1162d99203e7ab32a6b71fa045b/pyzmq-19.0.1-cp36-cp36m-manylinux1_x86_64.whl (1.1 MB)
|████████████████████████████████| 1.1 MB 1.6 MB/s
Collecting qtpy
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/cd/fd/9972948f02e967b691cc0ca1f26124826a3b88cb38f412a8b7935b8c3c72/QtPy-1.9.0-py2.py3-none-any.whl (54 kB)
|████████████████████████████████| 54 kB 46.2 MB/s
Collecting testpath
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/1b/9e/1a170feaa54f22aeb5a5d16c9015e82234275a3c8ab630b552493f9cb8a9/testpath-0.4.4-py2.py3-none-any.whl (163 kB)
|████████████████████████████████| 163 kB 76.6 MB/s
Collecting mistune<2,>=0.8.1
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/09/ec/4b43dae793655b7d8a25f76119624350b4d65eb663459eb9603d7f1f0345/mistune-0.8.4-py2.py3-none-any.whl (16 kB)
Collecting entrypoints>=0.2.2
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/ac/c6/44694103f8c221443ee6b0041f69e2740d89a25641e62fb4f2ee568f2f9c/entrypoints-0.3-py2.py3-none-any.whl (11 kB)
Collecting bleach
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/9a/1e/7d6cb3b27cd2c490558349ca5d5cc05b390b017da1c704cac807ac8bd9fb/bleach-3.1.5-py2.py3-none-any.whl (151 kB)
|████████████████████████████████| 151 kB 48.8 MB/s
Collecting defusedxml
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/06/74/9b387472866358ebc08732de3da6dc48e44b0aacd2ddaa5cb85ab7e986a2/defusedxml-0.6.0-py2.py3-none-any.whl (23 kB)
Collecting pandocfilters>=1.4.1
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/4c/ea/236e2584af67bb6df960832731a6e5325fd4441de001767da328c33368ce/pandocfilters-1.4.2.tar.gz (14 kB)
Collecting jsonschema!=2.5.0,>=2.4
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/c5/8f/51e89ce52a085483359217bc72cdbf6e75ee595d5b1d4b5ade40c7e018b8/jsonschema-3.2.0-py2.py3-none-any.whl (56 kB)
|████████████████████████████████| 56 kB 50.4 MB/s
Requirement already satisfied: pexpect; sys_platform != "win32" in /root/Envs/test_envs/lib/python3.6/site-packages (from ipython>=4.0.0; python_version >= "3.3"->ipywidgets->jupyter) (4.8.0)
Requirement already satisfied: pickleshare in /root/Envs/test_envs/lib/python3.6/site-packages (from ipython>=4.0.0; python_version >= "3.3"->ipywidgets->jupyter) (0.7.5)
Requirement already satisfied: setuptools>=18.5 in /root/Envs/test_envs/lib/python3.6/site-packages (from ipython>=4.0.0; python_version >= "3.3"->ipywidgets->jupyter) (46.1.3)
Requirement already satisfied: backcall in /root/Envs/test_envs/lib/python3.6/site-packages (from ipython>=4.0.0; python_version >= "3.3"->ipywidgets->jupyter) (0.1.0)
Requirement already satisfied: jedi>=0.10 in /root/Envs/test_envs/lib/python3.6/site-packages (from ipython>=4.0.0; python_version >= "3.3"->ipywidgets->jupyter) (0.17.0)
Requirement already satisfied: decorator in /root/Envs/test_envs/lib/python3.6/site-packages (from ipython>=4.0.0; python_version >= "3.3"->ipywidgets->jupyter) (4.4.2)
Requirement already satisfied: six in /root/Envs/test_envs/lib/python3.6/site-packages (from traitlets>=4.3.1->ipywidgets->jupyter) (1.14.0)
Requirement already satisfied: python-dateutil>=2.1 in /root/Envs/test_envs/lib/python3.6/site-packages (from jupyter-client->jupyter-console->jupyter) (2.8.1)
Requirement already satisfied: wcwidth in /root/Envs/test_envs/lib/python3.6/site-packages (from prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0->jupyter-console->jupyter) (0.1.9)
Requirement already satisfied: MarkupSafe>=0.23 in /root/Envs/test_envs/lib/python3.6/site-packages (from jinja2->notebook->jupyter) (1.1.1)
Requirement already satisfied: ptyprocess; os_name != "nt" in /root/Envs/test_envs/lib/python3.6/site-packages (from terminado>=0.8.1->notebook->jupyter) (0.6.0)
Collecting webencodings
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/f4/24/2a3e3df732393fed8b3ebf2ec078f05546de641fe1b667ee316ec1dcf3b7/webencodings-0.5.1-py2.py3-none-any.whl (11 kB)
Collecting packaging
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/46/19/c5ab91b1b05cfe63cccd5cfc971db9214c6dd6ced54e33c30d5af1d2bc43/packaging-20.4-py2.py3-none-any.whl (37 kB)
Collecting pyrsistent>=0.14.0
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/9f/0d/cbca4d0bbc5671822a59f270e4ce3f2195f8a899c97d0d5abb81b191efb5/pyrsistent-0.16.0.tar.gz (108 kB)
|████████████████████████████████| 108 kB 50.8 MB/s
Collecting importlib-metadata; python_version < "3.8"
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/98/13/a1d703ec396ade42c1d33df0e1cb691a28b7c08b336a5683912c87e04cd7/importlib_metadata-1.6.1-py2.py3-none-any.whl (31 kB)
Collecting attrs>=17.4.0
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/a2/db/4313ab3be961f7a763066401fb77f7748373b6094076ae2bda2806988af6/attrs-19.3.0-py2.py3-none-any.whl (39 kB)
Requirement already satisfied: parso>=0.7.0 in /root/Envs/test_envs/lib/python3.6/site-packages (from jedi>=0.10->ipython>=4.0.0; python_version >= "3.3"->ipywidgets->jupyter) (0.7.0)
Collecting pyparsing>=2.0.2
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/8a/bb/488841f56197b13700afd5658fc279a2025a39e22449b7cf29864669b15d/pyparsing-2.4.7-py2.py3-none-any.whl (67 kB)
|████████████████████████████████| 67 kB 50.4 MB/s
Collecting zipp>=0.5
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/b2/34/bfcb43cc0ba81f527bc4f40ef41ba2ff4080e047acb0586b56b3d017ace4/zipp-3.1.0-py3-none-any.whl (4.9 kB)
Building wheels for collected packages: tornado, pandocfilters, pyrsistent
Building wheel for tornado (setup.py) ... done
Created wheel for tornado: filename=tornado-6.0.4-cp36-cp36m-linux_x86_64.whl size=422799 sha256=9a2529dd3aef448fbd77fe1cd57a418aaf9d562b51863163b97c9f2b9d87517a
Stored in directory: /root/.cache/pip/wheels/be/89/29/c4ee680e489359dc0a83d8bbd490125ef0f8e7cd11b3d46aeb
Building wheel for pandocfilters (setup.py) ... done
Created wheel for pandocfilters: filename=pandocfilters-1.4.2-py3-none-any.whl size=7856 sha256=d49f82ccddaecaaf218d79b548a38b23d5a1a788101df334af0b116fdb0e0cc4
Stored in directory: /root/.cache/pip/wheels/c5/11/1e/f7d80bdfb97b4ddc343370a97ac1d5a39857dbf5a657e110eb
Building wheel for pyrsistent (setup.py) ... done
Created wheel for pyrsistent: filename=pyrsistent-0.16.0-cp36-cp36m-linux_x86_64.whl size=114562 sha256=934dd3f2b690176b0c0ccf741fd0f9f5c9b9c6976a8ece0366d7b049e4516075
Stored in directory: /root/.cache/pip/wheels/df/29/b2/b909a67d062b3688f5767e02e498648aacfa8f7bb6d73293b7
Successfully built tornado pandocfilters pyrsistent
Installing collected packages: tornado, terminado, jupyter-core, pyzmq, jupyter-client, ipykernel, pyrsistent, zipp, importlib-metadata, attrs, jsonschema, nbformat, testpath, mistune, entrypoints, webencodings, pyparsing, packaging, bleach, defusedxml, pandocfilters, nbconvert, Send2Trash, prometheus-client, notebook, widgetsnbextension, ipywidgets, jupyter-console, qtpy, qtconsole, jupyter
Successfully installed Send2Trash-1.5.0 attrs-19.3.0 bleach-3.1.5 defusedxml-0.6.0 entrypoints-0.3 importlib-metadata-1.6.1 ipykernel-5.3.0 ipywidgets-7.5.1 jsonschema-3.2.0 jupyter-1.0.0 jupyter-client-6.1.3 jupyter-console-6.1.0 jupyter-core-4.6.3 mistune-0.8.4 nbconvert-5.6.1 nbformat-5.0.7 notebook-6.0.3 packaging-20.4 pandocfilters-1.4.2 prometheus-client-0.8.0 pyparsing-2.4.7 pyrsistent-0.16.0 pyzmq-19.0.1 qtconsole-4.7.4 qtpy-1.9.0 terminado-0.8.3 testpath-0.4.4 tornado-6.0.4 webencodings-0.5.1 widgetsnbextension-3.5.1 zipp-3.1.0
(test_envs) [root@iZuf60a8w2ct7p4wqkf5c3Z tmp]#
(test_envs) [root@iZuf60a8w2ct7p4wqkf5c3Z tmp]#
(test_envs) [root@iZuf60a8w2ct7p4wqkf5c3Z tmp]#
2. 創建Jupyter默認配置文件(test_envs) [root@iZuf60a8w2ct7p4wqkf5c3Z test]# jupyter notebook --generate-config
Writing default config to: /root/.jupyter/jupyter_notebook_config.py
3. 生成SHA1加密的密鑰,保存密鑰,如'sha1:XXXXXX'(test_envs) [root@iZuf60a8w2ct7p4wqkf5c3Z test]# ipython
Python 3.6.5 (default, Nov 3 2019, 15:42:46)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.14.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from notebook.auth import passwd
In [2]: passwd()
Enter password:
Verify password:
Out[2]: 'sha1:cf59ae74aaef:b7da8cf6f9132090eb48c5c81ab2f6265b7478dc'
In [3]: exit
4. 設置密鑰,修改配置文件在文件末尾增加c.NotebookApp.password = u'sha1:XXXXXX'
(test_envs) [root@iZuf60a8w2ct7p4wqkf5c3Z test]# vi /root/.jupyter/jupyter_notebook_config.py
# Configuration file for jupyter-notebook.
#---
# Application(SingletonConfigurable) configuration
#---
## This is an application.
## The date format used by logging formatters for %(asctime)s
#c.Application.log_datefmt = '%Y-%m-%d %H:%M:%S'
## The Logging format template
#c.Application.log_format = '[%(name)s]%(highlevel)s %(message)s'
## Set the log level by value or name.
#c.Application.log_level = 30
#---
# JupyterApp(Application) configuration
#---
## Base class for Jupyter applications
## Answer yes to any prompts.
#c.JupyterApp.answer_yes = False
## Full path of a config file.
#c.JupyterApp.config_file = ''
## Specify a config file to load.
#c.JupyterApp.config_file_name = ''
## Generate default config file.
#c.JupyterApp.generate_config = False
#---
# NotebookApp(JupyterApp) configuration
#---
## Set the Access-Control-Allow-Credentials: true header
#c.NotebookApp.allow_credentials = False
## Set the Access-Control-Allow-Origin header
#
"~/.jupyter/jupyter_notebook_config.py" 876L, 34416C
# since that configuration value indicates which environmental values to make
# available to the kernel. (JUPYTER_GATEWAY_ENV_WHITELIST env var)
#c.GatewayClient.env_whitelist = ''
## Additional HTTP headers to pass on the request. This value will be converted
# to a dict. (JUPYTER_GATEWAY_HEADERS env var)
#c.GatewayClient.headers = '{}'
## The password for HTTP authentication. (JUPYTER_GATEWAY_HTTP_PWD env var)
#c.GatewayClient.http_pwd = None
## The username for HTTP authentication. (JUPYTER_GATEWAY_HTTP_USER env var)
#c.GatewayClient.http_user = None
## The gateway API endpoint for accessing kernel resources
# (JUPYTER_GATEWAY_KERNELS_ENDPOINT env var)
#c.GatewayClient.kernels_endpoint = '/api/kernels'
## The gateway API endpoint for accessing kernelspecs
# (JUPYTER_GATEWAY_KERNELSPECS_ENDPOINT env var)
#c.GatewayClient.kernelspecs_endpoint = '/api/kernelspecs'
## The gateway endpoint for accessing kernelspecs resources
# (JUPYTER_GATEWAY_KERNELSPECS_RESOURCE_ENDPOINT env var)
#c.GatewayClient.kernelspecs_resource_endpoint = '/kernelspecs'
## The time allowed for HTTP request completion. (JUPYTER_GATEWAY_REQUEST_TIMEOUT
# env var)
#c.GatewayClient.request_timeout = 60.0
## The url of the Kernel or Enterprise Gateway server where kernel specifications
# are defined and kernel management takes place. If defined, this Notebook
# server acts as a proxy for all kernel management and kernel specification
# retrieval. (JUPYTER_GATEWAY_URL env var)
#c.GatewayClient.url = None
## For HTTPS requests, determines if server's certificate should be validated or
# not. (JUPYTER_GATEWAY_VALIDATE_CERT env var)
#c.GatewayClient.validate_cert = True
## The websocket url of the Kernel or Enterprise Gateway server. If not
# provided, this value will correspond to the value of the Gateway url with 'ws'
# in place of 'http'. (JUPYTER_GATEWAY_WS_URL env var)
#c.GatewayClient.ws_url = None
c.NotebookApp.password = u'sha1:cf59ae74aaef:b7da8cf6f9132090eb48c5c81ab2f6265b7478dc'
"~/.jupyter/jupyter_notebook_config.py" 877L, 34503C written
5. 運行Jupyter(--ip指定ip,--port指定埠 --no-browser不打開瀏覽器,--allow-root允許root運行)(test_envs) [root@iZuf60a8w2ct7p4wqkf5c3Z test]# jupyter notebook --ip=0.0.0.0 --port 8889 --no-browser --allow-root
[I 15:14:55.419 NotebookApp] The port 8888 is already in use, trying another port.
[I 15:14:55.426 NotebookApp] Serving notebooks from local directory: /home/app/test
[I 15:14:55.426 NotebookApp] The Jupyter Notebook is running at:
[I 15:14:55.426 NotebookApp] http://iZuf60a8w2ct7p4wqkf5c3Z:8889/
[I 15:14:55.426 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
6. 打開瀏覽器輸入地址使用