AdSense

網頁

2025/6/11

VSCode Python venv Import "flask" could not be resolved

VScode編輯venv環境下的Python程式中匯入的flask函式庫無法被解析。


問題

例如「Python Flask Hello World」範例中的demo.py



問題是因為VSCode和專案venv環境使用的是不同的Python interpreter,VSCode預設的Python interpreter認不得venv環境安裝的Flask。


解決

在VSCode按Ctrl+Shift+P開啟Command Palette,輸入"Python:Select Interpreter"並點選[Python:Select Interpreter],



然後選擇[Enter interpreter path...],



然後點選[Find...]彈出檔案目錄,選擇venv環境下的python.exe,例如範例中專案目錄下的.venv\Scripts\python.exe即可解決。




沒有留言:

AdSense