我已經在網上搜索了很長一段時間,似乎無法找到解決我的問題的方法。我安裝了 Pylance(最新的 Microsoft Python 解釋器),但似乎根本無法禁用 linting。我嘗試了很多選擇,但沒有一個有效。這是我的代碼中現在多么煩人的 linting 的屏幕截圖。我的 VSCode 設置文件如下所示:{ // "python.pythonPath": "C://Anaconda3//envs//py34//python.exe", // "python.pythonPath": "C://Anaconda3_2020//python.exe", // "python.pythonPath": "C://Anaconda3_2020_07//python.exe", "python.pythonPath": "C://Anaconda3//python.exe", "python.analysis.disabled": [ "unresolved-import" ], "editor.suggestSelection": "first", "editor.fontSize": 15, "typescript.tsserver.useSeparateSyntaxServer": false, "workbench.colorTheme": "Monokai ST3", "workbench.colorCustomizations": { "editor.background": "#000000", "statusBar.background": "#000000", "statusBar.noFolderBackground": "#212121", "statusBar.debuggingBackground": "#263238" }, "window.zoomLevel": 0, "editor.renderLineHighlight": "none", "editor.fontFamily": "Meslo LG L", "editor.tabCompletion": "on", "editor.parameterHints.enabled": true, "python.terminal.executeInFileDir": true, "python.terminal.launchArgs": [ "-u" ], "terminal.integrated.shell.windows": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "editor.lineHeight": 0, "workbench.editor.scrollToSwitchTabs": true, "python.autoComplete.showAdvancedMembers": false, "python.languageServer": "Pylance", "python.linting.enabled": false, "python.linting.pylintEnabled": false, "python.linting.lintOnSave": false, "python.linting.flake8Enabled": false, "python.linting.mypyEnabled": false, "python.linting.banditEnabled": false, "python.linting.pylamaEnabled": false, "python.linting.pylintArgs": [ "--unsafe-load-any-extension=y", "--load-plugin", "pylint_protobuf", "--disable=all", "--disable=undefined-variable", ],}https://i.stack.imgur.com/DIryp.png 有什么想法嗎?任何幫助深表感謝。
4 回答

慕田峪4524236
TA貢獻1875條經驗 獲得超5個贊
禁用語言服務器的工作原理如 maxm 所回答。這也將禁用其他功能。
相反,只需在 .vscode 的 settings.json 中進行以下設置,即可忽略 pylance 的警告和錯誤。
"python.analysis.ignore": [
"*"
]
其他功能將在不禁用 pylance 的情況下出現。

海綿寶寶撒
TA貢獻1809條經驗 獲得超8個贊
消除圖片中這些警告的一種方法是通過設置禁用 Pylance "python.languageServer": "None"(已在接受的答案中提到)。
但您基本上禁用了語言服務器,這意味著您將失去Pylance 的所有幫助。我認為這不是你想要的。
相反,您可以排除某些路徑,而這些路徑根本不會進行類型檢查。我通常為Python的標準庫做這件事。
在以前版本的 Pylance 中,您可以在工作區的根目錄中創建一個pyrightconfig.json(Pylance 是在 Pyright 之上構建的,這就是原因)并將其放入其中(有關更多信息 -單擊):
{ ????"ignore":?[ ????????"path?to?your?third-party?package?or?stdlib?or?..." ????],}
但從現在( 2022年10月)開始,你可以直接設置為settings.json
:
"python.analysis.ignore":?["path?to?your?third-party?package?or?stdlib?or?...",?]
請記住,您可以在 paths 中使用通配符。這樣您的自定義模塊只會被檢查。
如果你想完全禁用類型檢查:
"python.analysis.typeCheckingMode":?"off"
添加回答
舉報
0/150
提交
取消