第 0 章 · 環境準備
VS Code 設定
🎯 學習目標¶
- 安裝 VS Code 並設定為 Python 編輯器
- 安裝 Python 與 Jupyter 兩個必備擴充
- 學會用 VS Code 跑 .py 檔和 .ipynb notebook
- 認識 settings.json 怎麼改
⬇️ 安裝 VS Code¶
- 開瀏覽器到 https://code.visualstudio.com/
- 下載安裝檔並執行
- macOS: 拖到 Applications
- Windows: 一直下一步
- Linux: 用
snap或apt安裝
🔌 安裝必備擴充¶
打開 VS Code,按 Cmd+Shift+X(macOS)或 Ctrl+Shift+X(Windows)打開擴充市集,搜尋並安裝:
| 擴充 ID | 用途 |
|---|---|
ms-python.python | Python 語言支援(必裝) |
ms-toolsai.jupyter | Jupyter notebook 支援 |
ms-python.vscode-pylance | Python 智慧提示 |
njpwerner.autodocstring | 自動 docstring |
⚙️ 設定 Python interpreter¶
- 按
Cmd+Shift+P打開命令選擇 - 輸入 "Python: Select Interpreter"
- 選擇你剛安裝的 Python 3.11+
✏️ 第一支 .py 檔¶
- 新增檔案
hello.py - 輸入:
- 按右上 ▶︎ 執行(或
Ctrl+F5) - 終端機會問你名字,輸入後看到歡迎訊息
📓 Jupyter notebook 模式¶
- 安裝 Jupyter 擴充後,
.ipynb檔案可以直接開 - 按
+ Code加 cell - 輸入
print('Hello') - 按
Shift+Enter執行
🎨 推薦設定(settings.json)¶
{
"editor.fontSize": 14,
"editor.fontFamily": "JetBrains Mono, monospace",
"editor.minimap.enabled": false,
"editor.formatOnSave": true,
"python.defaultInterpreterPath": "python3"
}
❗ 常見錯誤¶
- VS Code 找不到 Python → 重選 interpreter
- 擴充裝了沒反應 → 重啟 VS Code
- 中文輸入亂碼 → 終端機設定 UTF-8
📚 延伸閱讀¶
下一課:0.4 Hello, Python! — 寫你人生第一支程式 ✨