使用 visual studio code 進行 python 開發時,有時需要指定為在某個 anaconda 環境中運行
1. 安裝 Anaconda 后,嘗試 Powershell 運行 conda --version,若提示無法將“conda”項識別為 cmdlet、函數、腳本文件或可運行程序的名稱,需要在環境變量中添加 conda 路徑
默認路徑在:C:\Users\Alan\anaconda3\Scripts
添加 conda 路徑后,重啟 Powershell 執行 conda --version,若提示需要執行 conda init <shellname>,則執行:conda init powershell 並重啟
2. 再次啟動 Powershell 紅色文字提示錯誤:
無法加載文件 c:\users\alan\documents\windowspowershell\profile.ps1,因為在此系統上禁止運行腳本
需要在 Powershell 中執行 set-executionpolicy remotesigned 並重啟
3. 在 vs code 中,在軟件左下角選擇 python 環境,選擇對應的 conda env 的 python 即可