Try   HackMD

AI LINE Bot練功坊-L3 開發環境建置

Python 安裝

Windows安裝
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. 官網下載適當的版本安裝(以python3.12.2為範例)

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

  2. 執行安裝檔(.exe)

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

  3. 勾選「Add python.exe to PATH」,並選擇「Install Now」進行安裝

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

  4. 出現以下畫面即為安裝完成

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

  5. 將Python加入環境變數(若步驟3有勾選Add python.exe to PATH 則忽略此步驟)
    (1) 進入控制台後點選系統及安全性

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

    (2) 點選系統

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

    (3) 點選系統進階設定

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

    (4) 點選環境變數

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

    (5) 點選Path後點擊下方編輯

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

    (6) 點選新增

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

    (7) 將Python的兩個路徑新增進去(要用你自己的路徑)

    C:\Users\USER\AppData\Local\Programs\Python\Python312\ C:\Users\USER\AppData\Local\Programs\Python\Python312\Scripts\

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

  6. 查看Python版本
    在命令提示字元中輸入以下指令

    ​​​​python --version
    

    出現以下畫面即為安裝成功

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

MacOS安裝
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. 官網下載適當的版本安裝(以python3.12.2為範例)

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

  2. 執行安裝檔(.pkg)

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

  3. 依序安裝流程點選安裝

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

  4. 出現以下畫面即為安裝完成!

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

VScode 安裝

Windows安裝
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. 官網下載安裝檔

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

  2. 執行安裝檔(.exe)

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

  3. 同意使用者條款

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

  4. 除了"針對支援的檔案類型將Code註冊為編輯器"不要勾,其他都勾起

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

  5. 安裝完成會自動打開VScode

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

MacOS安裝
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. 官網下載安裝檔

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

  2. 將下載好的zip檔解壓縮

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

  3. 完成解壓縮後將執行檔拉進應用程式資料夾中

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

Python Extension

  1. 點選Extensions頁籤

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

  2. 搜尋Python套件並安裝

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

Ngrok 安裝

Windows安裝
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. ngrok官網註冊帳號

    image

  2. 登入後找到下載的頁籤

    image

  3. 複製設置token指令

    image

  4. 解壓縮下載的檔案

    image

  5. 執行ngrok.exe,並貼上剛剛複製的指令

    image

    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 →
    紅框的路徑位置必須和剛剛解壓縮後的路徑是一樣的

  6. 成功設定token會出現紅框內容

    image

  7. 建立臨時伺服器

    ​​​​ngrok http <port>
    

    image

    按下Enter

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

    臨時伺服器建立成功

MacOS安裝
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. ngrok官網註冊帳號

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

  2. 登入後找到下載的頁籤

    image

  3. 複製設置token指令

    image

  4. 解壓縮下載的檔案

    image

  5. 點選前往資料夾

    image

  6. 進入/usr/local/bin 路徑資料夾中

    image

  7. 將解壓縮好的ngrok應用程式拉進該路徑資料夾中

    image

  8. 雙擊執行ngrok,直到出現[程序完成]

    image

  9. 開啟終端機,將複製的指令打上執行

    image

  10. 成功設定token會出現紅框內容

    image

  11. 建立臨時伺服器

    ​​​​ngrok http <port>
    

    image

    按下Enter

    image

    臨時伺服器建立成功

建立Python虛擬環境

Windows安裝
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. 建立一個空的資料夾存放虛擬環境

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

  2. 打開資料夾並在上方輸入cmd並按下Enter

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

    這樣可以打開命令提示字元

  3. 建立python虛擬環境

    ​​​​python -m venv {環境名稱}
    

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

    執行成功後會有一個linebot的資料夾在venv中

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

  4. 需要啟動activate.bat才可以啟動虛擬環境

    切換路徑指令

    ​​​​cd linebot/Scripts
    

    啟動activate.bat指令

    ​​​​activate.bat
    

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    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 →
    若使用powershell的指令則為

    ​​​​activate.ps1
    

MacOS安裝
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. 建立一個空的資料夾存放虛擬環境

    image

  2. 點擊左上角 終端機 Terminal 選項,並點選 新增終端

    image

  3. 輸入指令,建立python虛擬環境

    ​​​​python3 -m venv {環境名稱}
    

    image

  4. 建立完成後輸入以下指令,切換路徑至該環境資料夾中

    ​​​​cd {環境名稱}
    

    image

  5. 啟動bin資料夾下的activate指令

    ​​​​source bin/activate
    

    image
    image

這樣就成功啟動虛擬環境了

安裝python套件

Windows安裝
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. 建立專案的資料夾

    image

  2. 在資料夾中新增requirements.txt

    image

  3. requirements.txt中輸入

    ​​​​line-bot-sdk==3.7.0
    ​​​​flask==3.0.0
    

    image

    輸入後存檔

  4. 複製 requirements.txt 路徑

    image

    image

  5. 安裝套件

    ​​​​pip install -r <requirements.txt所屬路徑>
    

    image

  6. 安裝完成

    image

MacOS安裝
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. 建立專案資料夾

    image

  2. 開啟軟體-文字編輯器 (系統原有)

    image

  3. 點擊新增文件

    image

  4. 點擊上方格式>製作純文字格式選項

    image

  5. 將相關所需套件輸入至文件中

    ​​​​line-bot-sdk==3.7.0
    ​​​​flask==3.0.0
    

    image

  6. 輸入完成後,將檔案以requirements.txt存入專案資料夾中

    image

  7. 進到專案資料夾中,將requirements.txt檔案路徑複製起來

    image

  8. 回到VSCode中,並在終端機中輸入以下指令

    ​​​​pip install -r <requirements.txt所屬路徑>
    

    image

  9. 安裝成功

    image

查看環境套件指令

pip list

image

離開虛擬環境指令

deactivate

image

Youtube 課程影片

關於我們

image 國立臺北教育大學 教育大數據微學程

先修微課程

🤖 AI LineBot 練功坊系列課程
從入門到精通,學習如何開發並應用 LINE Bot,讓你輕鬆掌握最前沿的聊天機器人技術。

👨‍💻 Python 初學小教室
針對零基礎學員設計,循序漸進地教授 Python 基本語法及實作技巧,幫助你快速上手。

📊 統計學小教室
系統講解統計學理論及其應用,適合想要提升數據分析能力的學習者。

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →
Facebook
Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →
Instagram
Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →
Threads
Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →
YouTube
Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →
Line官方帳號

相關教材連結

◀◀◀ L02 建立LINE Bot 官方帳號註冊 ◀◀◀
▶▶▶ L04 開發環境建置 ▶▶▶