本文示例檔案已上傳至我的
Github
倉庫https://github.com/CNFeffery/DataScienceStudyNotes
1 簡介
jupyter lab
是我最喜歡的編輯器,在過往的文章中也給大家介紹過很多相關資源和實用外掛,但本文要給大家介紹的jupyter lab
外掛elyra
,絕對是我使用過的最強大的jupyter lab
外掛沒有之一,因為它的核心功能就是幫助我們解決資料分析工作中非常重要的問題——搭建工作流。

2 利用elyra搭建工作流
在安裝elyra
外掛集之前,請確保你的jupyter lab
版本在2.0
及以上,並且已經安裝好了nodejs
也就是所有jupyter lab
擴充外掛都需要的依賴。
不像常規的jupyter lab
外掛的安裝方法,我們執行下列命令即可安裝elyra
下整合的多個外掛:
pip install --upgrade elyra && jupyter lab build
安裝完之後,你的jupyter lab
操作介面外觀會發生一些變化,我們先記住在安裝elyra
之前我們的jupyter lab
介面長啥樣(我使用的主題感興趣的朋友可以通過jupyter labextension install jupyterlab-tailwind-theme
來安裝):

而在安裝完成重啟jupyter lab
之後,除了左上角的jupyter
logo變化了之外,還新增了圖中我用紅框框選出來的地方:

接下來我們就來介紹如何利用elyra
互動式地搭建工作流。
elyra
賦予了我們通過互動的方式將若干個ipynb
檔案組織成工作流的能力,為了方便演示,這裡我們建立幾個帶有簡單流程程式碼的ipynb
檔案:




接著我們在Launcher頁面點選Pipeline Editor
開啟用來互動式編輯notebook流水線的介面:


直接將側邊欄中對應的step1.ipynb
檔案拖拽進來:

點選流水線介面中ipynb
檔案對應節點右側的三個圓點,可以開啟更多功能選項:

因為我們是本地環境,所以這裡只需要在properties
下必填引數Runtime Image
中隨便選一個就行:

儲存之後,就完成了本地環境下單個節點的必要引數設定,同樣的將其他ipynb
檔案拖拽進來,各自配置好必要引數再如圖13所示將各節點聯結起來:

這樣我們的流水線就搭建好了,是不是非常滴好玩~,接著點選左上角的執行按鈕,輸入流水線名稱後即可開始執行我們的工作流:

工作流執行成功之後也會有提示:

如果工作流執行到某個節點發生程式錯誤,也會有非常人性化的提示:

對應出錯的ipynb
錯誤程式碼塊上方,elyra
也會幫我們建立記錄錯誤資訊的markdown
單元格:

最好用的是,配合魔術命令%store
,我們就可以跨notebook
傳遞全域性變數,而不需要再往外寫出先前節點的結果檔案:
利用%store 變數名
將某個變數轉化為跨kernel
的全域性變數:

利用%store -r 變數名
將跨kernel
全域性變數中的指定變數載入到當前kernel
中:

而除了搭建工作流這個核心功能外,elyra
還有很多其他的實用功能,感興趣的朋友可以前往官方文件(https://elyra.readthedocs.io/en/latest/)自行閱讀學習。

以上就是本文的全部內容,歡迎在評論區與我進行討論~