2021-09-09

vscode的鳥bug,跑python預設都只會在powershell跑

在windows上,不管怎麼修改terminal default profile為command prompt(cmd),只要點右上的執行按鈕,就是只會用powershell執行python,而且還無法正常載入conda env環境(還是linux好)。

解決方式:

一、先用管理員進powershell執行 set-executionpolicy remotesigned

二、再到vscode建立python的launch.json,加入如下(參考開始選單中conda呼叫poweshell的捷徑參數修改):

"configurations": [

    {

        "name": "Python: 目前檔案",

        "type": "python",

        "request": "launch",

        "program": "${file}",

        "console": "integratedTerminal",

        "args": [

            "-ExecutionPolicy",

            "ByPass" ,

            "-NoExit",

            "-Command",

            "& 'C:\\Users\\User\\miniconda3\\shell\\condabin\\conda-hook.ps1' ; conda activate 'C:\\Users\\User\\miniconda3' "

        ]

    }

]

 ref:
https://stackoverflow.com/questions/54828713/working-with-anaconda-in-visual-studio-code
https://stackoverflow.com/questions/56450606/how-to-add-anaconda-powershell-to-vscode/61879466#61879466
https://docs.microsoft.com/zh-tw/powershell/scripting/dev-cross-plat/vscode/using-vscode?view=powershell-7.1#workspace-debugging

沒有留言:

張貼留言