Try   HackMD

jupyterlab 教學

環境介紹

  • 安裝Anaconda

    • 先到Anaconda官網(https://www.anaconda.com/download/),下載所需作業系統(有Windows、macOS和 Linux可選擇)的Anaconda版本
    • 詳細流程參考https://medium.com/python4u/anaconda%E4%BB%8B%E7%B4%B9%E5%8F%8A%E5%AE%89%E8%A3%9D%E6%95%99%E5%AD%B8-f7dae6454ab6
  • 從Anaconda首頁點選Launch jupyterlab 即可下載

    • Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →

功能介紹

起始畫面介紹

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

  • 左上角的 “+” 為新增 Launcher
  • 資料夾中包含一個+的圖示為新增資料夾
  • 一個箭頭網上的圖示為上傳檔案
  • – 何謂launcher
  • – 中文名稱為啟動器,用於啟動使用者需要的服務,像是撰寫Python,R…等平台提供之語言。

分為 Notebook 和 Console 以及 Other 兩種介面可供撰寫程式使用。

編寫環境介紹

  1. Notebook:
    • 筆記本形式寫code,適合完整的撰寫,例如作業、練習、上課筆記…等,在R裡面像是.Rmd。

環境教學如下圖

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

  • 右上角圈起來的部分為使用的kernel,像是這張圖,就是說明正在使用python3的kernel
  • 中間圈起來寫著code的部分,是提供使用者做型態轉換,型態分為Code,Markdown,Raw三種。
  • – Code : 可以撰寫使用者所選kernel的語言,此處為python。
  • – Markdown : 可以撰寫Markdown的語法,一種用於做筆記的語法。
  • – Raw : 單純文字記錄,案執行後只會呈現原本文字。

自動補全

與大多數本地IDE 相同,輸入部分代碼之後按tab 鍵,即可自動補全。Jupyter Lab 中的自動補全顯示比之前Jupyter Notebook 的要友好,通過不同的顏色和圖標。顯示出了補全的類型。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

問號查看詳細文檔

在函數或變量等後面添加一個問號(?),執行之後,即可查看對應的詳細文檔:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

  1. Console:
    • 這個撰寫程式介面時和測試使用。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

  1. Other:
    • 此處有兩個功能,一個是terminal,另一個是Text Editor。
  • Terminal : 會呈現的是你在centos作業系統(遠端電腦的概念)上的工作環境(使用者A、使用者B),每個人都會有自己的工作環境。
    – 更多linux使用方式後面會教。

  • Text Editor : 單純文字編輯器,可以透過這個編輯器寫你要寫的程式,但記得存檔時要更改副檔名(like .c .py .R)
    – 以下截圖為撰寫一個.c檔的範例。

Step 1. 打開Text Editor 並寫入程式碼,這裡會發現檔名為.txt。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Step 2. 將檔案存檔後,更改名稱及副檔名。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

更改完成後,會發現文字變色,也更容易識別語法,建議同學們在使用的時候先將檔名及副檔名更改為你要編寫的程式。

執行中的程式

點選jupyterlab旁的 "Running"可以看到你正在執行的內容。

如果有沒在使用的內容,請終止它運作,沒關掉會佔用運算資源

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

簡單Linux教學

Linux簡介

  • Linux
    • 開放原始碼的OS
    • 任何個人和機構都可以自由地使用 Linux 的所有底層原始碼,也可以自由地修改和再發布。
    • 模仿Unixe
    • 很多版本 Debian, Fedora, Red Hat(Centos)
    • 適合伺服器使用

Linux的常用命令

  • cd : change directory , R:setwd()
  • ls : list file, R:ls()
  • pwd : print working directory, R:getwd()

進入黑畫面 Terminal

介紹根目錄

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

  • 進來terminal後可以看到 [~ mars]
    • 使用者的名稱,這裡是mars
    • 波浪符號~ 在linux系統中代表"用戶的根目錄"

何謂用戶的根目錄

  • 請你們把它想成家的意思,然後一個家可以有很多個資料夾,所以你可以透過 cd ~ 快速回到根目錄進去其他資料夾。

ls 的用法

  • 了解了根目錄後,可以透過ls指令查詢根目錄的資料夾有什麼內容。

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

    • 你們可以發現根目錄列出來的資料夾旁邊跟圖形話介面中Files選項的內容是一樣的。
    • 所以可以透過指令去打開資料夾,也可以透過旁邊圖型化介面的方式點選打開資料夾。

cd 的用法

  • 透過ls找到我們要進去的資料夾後即可透過cd指令進入。

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

    • 這裡我們選擇進入rmis_102_2019這個資料夾
    • [shaomin@hadoop2 ~]$ cd mis102_2019/
    • 上面是下指令前的樣子,指令是 cd 加上資料夾名稱。
    • [shaomin@hadoop2 mis102_2019]$
    • 指令執行完後,會發現波浪符號變成剛剛的資料夾名稱,表示成功進入資料夾。
    • 底下是再用 ls 看一下資料夾內容,以及透過圖形化介面點選的方式 對照的影片。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

pwd 的用法

  • 這時候大家應該會想說,我如果開很多個資料夾,要怎麼知道我現在的位子在哪裡?
  • 使用pwd可以得知目前的位置。當然jupyterlab的圖形化介面也會顯上,如下圖紅圈位置。
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

    為何pwd後會出現"/home/shaomin"這兩層,其實這兩層就是"~波浪符號"的絕對路徑。

絕對路徑 & 相對路徑

  • 相對路徑 : 是相對於現在目錄的路徑表示,也就是你現在這個檔案在哪裡,這個目錄的路徑起始點就在哪裡。
  • 絕對路徑 : 是一個絕對位置,他不會隨著檔案位置的變換而改變他的路徑。

假設今天地球是一個電腦,也是這台電腦的根目錄 “/home/earth”
[user@earth ~]$
地球裡面有七大洲,每個州是一個資料夾"/home/earth/state"

    [user@earth ~]$ cd state 
    [user@earth state]$ ls
    Asia Europe Africa Oceania 
    South_America North_America Antarctica

台灣屬於亞洲,高雄又屬於台灣,所以以上訴例子,高雄的絕對路徑就是"/home/earth/state/Asia/Taiwan/Kaohsiung"

想必各位都了解絕對路徑了

再講相對路徑前,先介紹路徑的幾個特殊符號
-「.」是代表目前所在目錄
-「..」是代表上層目錄,若目前已經是根目錄則依然為目前所在目錄

現在假設我的當前位置在台北,所以路徑如下

    [user@earth Taipei]$ pwd
    /home/earth/state/Asia/Taiwan/Taipei

如果現在我在台北,我要去高雄,因為前面的路徑大致相同,所以這裡可以透過相對路徑的方式,更快地進入高雄這個資料夾,不需要把絕對路徑打出來

​​  [user@earth Taipei]$ cd ../Kaohsiung
​​  [user@earth Kaohsiung]$

換句話說: 就是我如果在台北,要去高雄不用經過其他state,可以透過相對路徑過去。當然也可以從台北透過相對路徑去美國加州,但那個應該不是個好選擇。

練習

『同學練習把我們的"BBQ.ipynb"設定到對應的位址後,讀入此檔案』