2020年4月9日 星期四

Python 學習筆記 : 安裝 JupyterLab

昨天測試 Sympy 發現在 Python IDLE 或 Shell 介面下無法漂亮地顯示積分式, 因為數學運算式需要 LaTex 才能顯示, 而這必須用以網頁為介面的 Jupyter Notebook 才行, 這可利用 Jupyter 官網上提供的線上版 Jupyter try 來測試 :

https://jupyter.org/try

Jupyter 測試網頁上提供了經典的 Jupyter Notebook 與新版的 JupyterLab 兩種介面 :




其中 JupyterLab 是 Notebook 的下一代產品, 除了將原有 Notebook 的功能整合在一起外還加進了更多新功能, 參考 :

Jupyterlab:超強的下一代Jupyter Notebook
Python 學習筆記 : 安裝 SymPy 套件
Jupyter Notebook 介紹 &安裝方式
[Day02]使用 Jupyter notebook來寫python
Jupyter Notebook 使用技巧彙整:建置不同程式語言的核心

JupyterLab 說明文件參考 GitHub :

https://github.com/jupyterlab/jupyterlab

除了使用方便的線上版外, 也可以在本機中安裝 JupyterLab 以避免網路不通時無法使用了. 安裝方式很簡單, 就是直接用 pip3 安裝 jupyterlab 套件 :

pip3 install jupyterlab

D:\>pip3 install jupyterlab
Collecting jupyterlab
  Downloading jupyterlab-2.1.0-py3-none-any.whl (7.8 MB)
Collecting notebook>=4.3.1
  Downloading notebook-6.0.3-py3-none-any.whl (9.7 MB)
Collecting tornado!=6.0.0,!=6.0.1,!=6.0.2
  Downloading tornado-6.0.4-cp37-cp37m-win_amd64.whl (417 kB)
Requirement already satisfied: jinja2>=2.10 in c:\python37\lib\site-packages (from jupyterlab) (2.10.1)
Collecting jupyterlab-server>=1.1.0
  Downloading jupyterlab_server-1.1.0-py3-none-any.whl (29 kB)
Requirement already satisfied: traitlets>=4.2.1 in c:\python37\lib\site-packages (from notebook>=4.3.1->jupyterlab) (4.3.2)
Requirement already satisfied: ipython-genutils in c:\python37\lib\site-packages (from notebook>=4.3.1->jupyterlab) (0.2.0)
Collecting prometheus-client
  Downloading prometheus_client-0.7.1.tar.gz (38 kB)
Collecting jupyter-client>=5.3.4
  Downloading jupyter_client-6.1.2-py3-none-any.whl (106 kB)
Collecting jupyter-core>=4.6.1
  Downloading jupyter_core-4.6.3-py2.py3-none-any.whl (83 kB)
Collecting pyzmq>=17
  Downloading pyzmq-19.0.0-cp37-cp37m-win_amd64.whl (1.1 MB)
Collecting nbformat
  Downloading nbformat-5.0.5-py3-none-any.whl (170 kB)
Collecting terminado>=0.8.1
  Downloading terminado-0.8.3-py2.py3-none-any.whl (33 kB)
Collecting nbconvert
  Downloading nbconvert-5.6.1-py2.py3-none-any.whl (455 kB)
Collecting ipykernel
  Downloading ipykernel-5.2.0-py3-none-any.whl (117 kB)
Collecting Send2Trash
  Downloading Send2Trash-1.5.0-py3-none-any.whl (12 kB)
Requirement already satisfied: MarkupSafe>=0.23 in c:\python37\lib\site-packages (from jinja2>=2.10->jupyterlab) (1.1.1)
Requirement already satisfied: requests in c:\python37\lib\site-packages (from jupyterlab-server>=1.1.0->jupyterlab) (2.21.0)
Collecting jsonschema>=3.0.1
  Downloading jsonschema-3.2.0-py2.py3-none-any.whl (56 kB)
Collecting json5
  Downloading json5-0.9.4-py2.py3-none-any.whl (17 kB)
Requirement already satisfied: six in c:\python37\lib\site-packages (from traitlets>=4.2.1->notebook>=4.3.1->jupyterlab) (1.12.0)
Requirement already satisfied: decorator in c:\python37\lib\site-packages (from traitlets>=4.2.1->notebook>=4.3.1->jupyterlab) (4.3.2)
Requirement already satisfied: python-dateutil>=2.1 in c:\python37\lib\site-packages (from jupyter-client>=5.3.4->notebook>=4.3.1->jupyterlab) (2.7.5)
Collecting pywin32>=1.0; sys_platform == "win32"
  Downloading pywin32-227-cp37-cp37m-win_amd64.whl (9.1 MB)
Collecting pywinpty>=0.5; os_name == "nt"
  Downloading pywinpty-0.5.7-cp37-cp37m-win_amd64.whl (1.3 MB)
Collecting mistune<2,>=0.8.1
  Downloading mistune-0.8.4-py2.py3-none-any.whl (16 kB)
Requirement already satisfied: pygments in c:\python37\lib\site-packages (from nbconvert->notebook>=4.3.1->jupyterlab) (2.3.1)
Collecting entrypoints>=0.2.2
  Downloading entrypoints-0.3-py2.py3-none-any.whl (11 kB)
Collecting testpath
  Downloading testpath-0.4.4-py2.py3-none-any.whl (163 kB)
Collecting pandocfilters>=1.4.1
  Downloading pandocfilters-1.4.2.tar.gz (14 kB)
Collecting defusedxml
  Downloading defusedxml-0.6.0-py2.py3-none-any.whl (23 kB)
Requirement already satisfied: bleach in c:\python37\lib\site-packages (from nbconvert->notebook>=4.3.1->jupyterlab) (3.1.0)
Requirement already satisfied: ipython>=5.0.0 in c:\python37\lib\site-packages (from ipykernel->notebook>=4.3.1->jupyterlab) (7.2.0)
Requirement already satisfied: certifi>=2017.4.17 in c:\python37\lib\site-packages (from requests->jupyterlab-server>=1.1.0->jupyterlab) (2018.11.29)
Requirement already satisfied: idna<2.9,>=2.5 in c:\python37\lib\site-packages (from requests->jupyterlab-server>=1.1.0->jupyterlab) (2.8)
Requirement already satisfied: urllib3<1.25,>=1.21.1 in c:\python37\lib\site-packages (from requests->jupyterlab-server>=1.1.0->jupyterlab) (1.24.1)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in c:\python37\lib\site-packages (from requests->jupyterlab-server>=1.1.0->jupyterlab) (3.0.4)
Collecting importlib-metadata; python_version < "3.8"
  Downloading importlib_metadata-1.6.0-py2.py3-none-any.whl (30 kB)
Requirement already satisfied: setuptools in c:\python37\lib\site-packages (from jsonschema>=3.0.1->jupyterlab-server>=1.1.0->jupyterlab) (40.9.0)
Collecting attrs>=17.4.0
  Downloading attrs-19.3.0-py2.py3-none-any.whl (39 kB)
Collecting pyrsistent>=0.14.0
  Downloading pyrsistent-0.16.0.tar.gz (108 kB)
Requirement already satisfied: webencodings in c:\python37\lib\site-packages (from bleach->nbconvert->notebook>=4.3.1->jupyterlab) (0.5.1)
Requirement already satisfied: backcall in c:\python37\lib\site-packages (from ipython>=5.0.0->ipykernel->notebook>=4.3.1->jupyterlab) (0.1.0)
Requirement already satisfied: prompt-toolkit<2.1.0,>=2.0.0 in c:\python37\lib\site-packages (from ipython>=5.0.0->ipykernel->notebook>=4.3.1->jupyterlab) (2.0.8)
Requirement already satisfied: jedi>=0.10 in c:\python37\lib\site-packages (from ipython>=5.0.0->ipykernel->notebook>=4.3.1->jupyterlab) (0.13.2)
Requirement already satisfied: colorama; sys_platform == "win32" in c:\python37\lib\site-packages (from ipython>=5.0.0->ipykernel->notebook>=4.3.1->jupyterlab) (0.4.1)
Requirement already satisfied: pickleshare in c:\python37\lib\site-packages (from ipython>=5.0.0->ipykernel->notebook>=4.3.1->jupyterlab) (0.7.5)
Collecting zipp>=0.5
  Downloading zipp-3.1.0-py3-none-any.whl (4.9 kB)
Requirement already satisfied: wcwidth in c:\python37\lib\site-packages (from prompt-toolkit<2.1.0,>=2.0.0->ipython>=5.0.0->ipykernel->notebook>=4.3.1->jupyterlab) (0.1.7)
Requirement already satisfied: parso>=0.3.0 in c:\python37\lib\site-packages (from jedi>=0.10->ipython>=5.0.0->ipykernel->notebook>=4.3.1->jupyterlab) (0.3.2)
Installing collected packages: prometheus-client, tornado, pywin32, jupyter-core, pyzmq, jupyter-client, zipp, importlib-metadata, attrs, pyrsistent, jsonschema, nbformat, pywinpty, terminado, mistune, entrypoints, testpath, pandocfilters, defusedxml, nbconvert, ipykernel, Send2Trash, notebook, json5, jupyterlab-server, jupyterlab
    Running setup.py install for prometheus-client ... done
    Running setup.py install for pyrsistent ... done
    Running setup.py install for pandocfilters ... done
Successfully installed Send2Trash-1.5.0 attrs-19.3.0 defusedxml-0.6.0 entrypoints-0.3 importlib-metadata-1.6.0 ipykernel-5.2.0 json5-0.9.4 jsonschema-3.2.0 jupyter-client-6.1.2 jupyter-core-4.6.3 jupyterlab-2.1.0 jupyterlab-server-1.1.0 mistune-0.8.4 nbconvert-5.6.1 nbformat-5.0.5 notebook-6.0.3 pandocfilters-1.4.2 prometheus-client-0.7.1 pyrsistent-0.16.0 pywin32-227 pywinpty-0.5.7 pyzmq-19.0.0 terminado-0.8.3 testpath-0.4.4 tornado-6.0.4 zipp-3.1.0

可見 JupyterLab 的相依模組很多, 但其實主程式不大, 全部加起來應該沒超過 20MB.

安裝好後在命令列下輸入 jupyter lab (有空格) 即可 :

D:\>jupyter lab
[I 16:14:37.424 LabApp] Writing notebook server cookie secret to C:\Users\User\AppData\Roaming\jupyter\runtime\notebook_cookie_secret
[I 16:14:38.818 LabApp] JupyterLab extension loaded from c:\python37\lib\site-packages\jupyterlab
[I 16:14:38.818 LabApp] JupyterLab application directory is c:\python37\share\jupyter\lab
[I 16:14:38.822 LabApp] Serving notebooks from local directory: D:\
[I 16:14:38.822 LabApp] The Jupyter Notebook is running at:
[I 16:14:38.823 LabApp] http://localhost:8888/?token=eddfbbf1a845eae56c6771caeb21ee3d5865ceebce0c7ec1
[I 16:14:38.823 LabApp]  or http://127.0.0.1:8888/?token=eddfbbf1a845eae56c6771caeb21ee3d5865ceebce0c7ec1
[I 16:14:38.824 LabApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 16:14:38.877 LabApp]

    To access the notebook, open this file in a browser:
        file:///C:/Users/User/AppData/Roaming/jupyter/runtime/nbserver-13296-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/?token=eddfbbf1a845eae56c6771caeb21ee3d5865ceebce0c7ec1
     or http://127.0.0.1:8888/?token=eddfbbf1a845eae56c6771caeb21ee3d5865ceebce0c7ec1
[I 16:14:42.275 LabApp] Build is up to date
[I 16:15:11.216 LabApp] Creating new notebook in /
[I 16:15:11.239 LabApp] Writing notebook-signing key to C:\Users\User\AppData\Roaming\jupyter\notebook_secret
[I 16:15:12.171 LabApp] Kernel started: 9d211394-b7c0-4a68-911b-a7298276104e
[I 16:17:11.457 LabApp] Saving file at /Untitled.ipynb


它會以網址 http://localhost:8888/lab 開啟預設瀏覽器網頁, 可用 Notebook 或 JupyterLab :




點選右邊的 JupyterLab 進去再點選 Python 3 :




輸入 Sympy 的積分式 :




果然繪製出美美的積分式了.

沒有留言 :