--- title: JupyterLab安裝 description: 使用Mac及Homebrew安裝JupyterLab及Python3.8 --- # JupyterLab 安裝 ###### 作者: TYT ###### 時間: 2023-02-01 ###### tags: `Jupyter`,`安裝` ## Homebrew安裝 請參閱[Homebrew官網](https://docs.brew.sh/Installation) ## JupyterLab安裝 1. 安裝JupyterLab ```linux! brew install jupyterlab ``` 2. 檢查安裝版本 ```javascript! jupyter lab --version ``` output: ``` 3.5.3 ``` 2. 檢查Jupyter core packages ```linux! jupyter --version ``` output: ```linux! Selected Jupyter core packages... IPython : 8.9.0 ipykernel : 6.21.0 ipywidgets : not installed jupyter_client : 8.0.2 jupyter_core : 5.2.0 jupyter_server : not installed jupyterlab : not installed nbclient : not installed nbconvert : not installed nbformat : not installed notebook : not installed qtconsole : not installed traitlets : 5.9.0 ``` 不相同也沒關係,就想知道個現在安裝了哪些core packages而已 ## Python 3.8安裝 因為專案需要安裝Python 3.8而已,沒有特殊原因 1. 安裝Python3.8 ```linux! brew install python@3.8 ``` 2. 檢查安裝狀態 ```linux! brew list | grep -i python ``` output: python@3.8 3. 檢查Python狀態 ```linux! python3.8 --version ``` output: ```linux! Python 3.8.16 ``` 如果沒有成功顯示的話,可能是沒有連結到,執行 ```linux! brew unlink python@3.8 && brew link python@3.8 ``` 再重複<檢查Python狀態>步驟 4. 將Python3.8加入JupyterLab kernel ```linux! python3.8 -m pip install ipykernel --user python3.8 -m ipykernel install --user --name=python3.8 --display-name=python3.8 ``` --name: 唯一識別碼,有相同識別碼時會overwrite --display-name: 顯示於JupyterLab上的名稱 5. 解安裝JupyterLab kernel Python3.8 ```linux! jupyter kernelspec uninstall unwanted-kernel-name ``` unwanted-kernel-name請替換成唯一識別碼 附註: 以安裝的JupyterLab版本為例,kernel清單中一定有python3的唯一識別碼,如果解安裝python3會持續的出現(但連接的位置不同),如果一定要求個清爽,可以將預安裝的Python的唯一識別碼改為python3,如下: ```linux! python3.8 -m pip install ipykernel --user python3.8 -m ipykernel install --user --name=python3 --display-name=python3.8 ``` ## 啟動JupyterLab ```linux! jupyter lab --notebook-dir=/project/path/ ``` --notebook-dir: 啟動時的起始目錄 可透過JupyterLab上方的工具列(Kernel > Change Kernel...)得知新的kernel有沒有安裝成功 ## 利用AppleScript寫成類APP 1. 打開Script Editer 2. 輸入 ```linux! tell application "Terminal" do script "jupyter lab --notebook-dir=/Users/TAI/Documents/Code" end tell ``` 3. 點擊Play按鈕(Run the Script)測試有沒有成功啟動JupyterLab 4. 輸出成Application: File > Export > File Format選擇Application > Save 5. 變更App icon請參閱[Apple官網](https://support.apple.com/zh-tw/guide/mac-help/mchlp2313/mac)