[英]How to run python3 code in VSCode? /bin/sh: 1: python: not found
我正在嘗試使用 python3 在 VSCode 中運行一個 python 文件。
我知道我可以通過簡單地設置為使用集成終端運行來修復,就像它在 python 上的Microsoft vscode 教程中所說的那樣。但是,我希望程序在output 選項卡中打印,而不占用終端 window。
標准的 coder runner launch.json
看起來像這樣;
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
我試圖在 settings.json 的 VSCode 中settings.json
我的 python 路徑
...
"python.pythonPath": "python3",
"code-runner.executorMap": {
"python3": "/usr/bin/python3"
}
我還為 python 設置了一個別名 -> python3(因為我的 ubuntu 20.04 不再帶有 python2)
alias python="python3"
但是,我不斷收到上述錯誤。 有任何想法嗎?
幾乎擁有它。 這段代碼
...
"python.pythonPath": "python3",
"code-runner.executorMap": {
"python3": "/usr/bin/python3"
}
應該
...
"python.pythonPath": "python3",
"code-runner.executorMap": {
"python": "/usr/bin/python3"
}
在 vscode 的終端中,輸入sudo apt install python-is-python3
。 安裝完成后,只需再次運行代碼並享受。
替代解決方案
"python.pythonPath": "python3",
"code-runner.executorMap": {
"python": "$pythonPath -u $fullFileName"
},
稍后,如果您安裝了 Code Runner,那么您必須通過進入 code-runner 將 go 進入設置:Executor Map “Edit in settings.json”並找到 Z23EEEB4347BDD26BDDZFC6B7EE9A3B7555
{
"workbench.colorTheme": "Default Dark+",
"code-runner.executorMap": {
"javascript": "node",
"java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
"c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"objective-c": "cd $dir && gcc -framework Cocoa $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"php": "php",
"python": "python -u",
"perl": "perl",
"perl6": "perl6",
"ruby": "ruby",
"go": "go run",
"lua": "lua",
"groovy": "groovy",
"powershell": "powershell -ExecutionPolicy ByPass -File",
"bat": "cmd /c",
"shellscript": "bash",
"fsharp": "fsi",
"csharp": "scriptcs",
"vbscript": "cscript //Nologo",
"typescript": "ts-node",
"coffeescript": "coffee",
"scala": "scala",
"swift": "swift",
"julia": "julia",
"crystal": "crystal",
"ocaml": "ocaml",
"r": "Rscript",
"applescript": "osascript",
"clojure": "lein exec",
"haxe": "haxe --cwd $dirWithoutTrailingSlash --run $fileNameWithoutExt",
"rust": "cd $dir && rustc $fileName && $dir$fileNameWithoutExt",
"racket": "racket",
"scheme": "csi -script",
"ahk": "autohotkey",
"autoit": "autoit3",
"dart": "dart",
"pascal": "cd $dir && fpc $fileName && $dir$fileNameWithoutExt",
"d": "cd $dir && dmd $fileName && $dir$fileNameWithoutExt",
"haskell": "runhaskell",
"nim": "nim compile --verbosity:0 --hints:off --run",
"lisp": "sbcl --script",
"kit": "kitc --run",
"v": "v run",
"sass": "sass --style expanded",
"scss": "scss --style expanded",
"less": "cd $dir && lessc $fileName $fileNameWithoutExt.css",
"FortranFreeForm": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"fortran-modern": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"fortran_fixed-form": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"fortran": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt"
}
}
改變這個
"python": "python -u",
或類似的東西,看起來像這樣
"python": "python3",
這是因為這是在 Python 3 中運行 python 代碼的新命令
2022年解決方案
步驟 1:轉到 Code Runner 擴展的設置
Step2:找到該部分
代碼運行器:執行器 Map
然后點擊
在設置中編輯。json
步驟 3:現在更改 python 的設置
前
"code-runner.executorMap": {
...
"python": "python -u"
...
}
將此更改為
"code-runner.executorMap": {
...
"python": "python3 -u"
...
}
sudo apt install python-is-python3
輸入上面的命令行,它將起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.