PyCharm 安裝教學 (for Mac User)
流程
- HomeBrew
- python3
- PyCharm
- 開啟 PyCharm 架設 fastAPI 框架
安裝HomeBrew
- 先確認有沒有安裝Xcode
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 →
如果macOS版本比較舊?
要不要用官方的GUI安裝
- 在終端機輸入
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- 如果提示說要安裝 Command Line Tools,請執行
xcode-select --install
如果遇到HomeBrew安裝問題,可參考此篇
利用 HomBrew 安裝 python3
- 在終端機輸入
- 檢查是否安裝成功
下載並安裝PyCharm
- 到官網下載安裝檔
- 選擇屬於你的CPU的安裝檔,Intel CPU 請選擇
.dmg (intel)
,M1或M2的用戶請選擇.dmg (Apple Silicon)
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 →
- 創建帳戶,設定密碼
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 →
- 點選 Apply now
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 →
- 填寫基本資料,學校信箱建議使用gapps,才收得到認證信件
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 →
- 回到帳號管理頁面,點選上方"Your Account"
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 →
- 點選右方選單中的"Linked email"
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 →
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 →
- 再回到帳號管理頁面,如果有出現下圖,代表License匯入成功
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 →
- 點選上圖紅色勾勾處按鈕進行啟用
- 拉到最下方後,點選"Accept"
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 →
開啟 PyCharm 安裝 fastAPI 框架
在每次開新專案時,都必須安裝對應的套件,因為在PyCharm裡,每個專案都有屬於他自己的虛擬環境。
-
開啟PyCharm
-
在開啟後登入已認證過的帳戶 (無教學圖示)
-
建立測試專案,點選 New Project
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 →
-
選擇 Pure Python 並設定好存放專案的路徑,按下 Create
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 →
-
按下執行按鈕,執行程式碼
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 →
-
在終端機輸入以下指令,安裝 fastAPI
註:皆為小寫,且是用 pip3 指令下載
-
繼續在終端機輸入以下指令,安裝 uvicorn 是搭配 fastAPI 在開方上的輔助工具
pip3 install "uvicorn[standard]"
-
測試,撰寫以下 python 程式碼
from typing import Union
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
return {"item_id": item_id, "q": q}
- 在終端機輸入以下指令
uvicorn main:app --reload
-
在終端機的結果當中點選網址,查看測試結果
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 →
過程中若遇到問題,可以參考官方文檔