[英]VS Code : Linter Pylint Not Installed; pip install pylint not working
[英]How to setup working directory in VS Code for pylint?
我有一個具有這種結構的項目:
├── .git
├── .gitignore
├── README.md
├── requirements.txt
└── src
Pylint 默認從項目根目錄運行,我的所有導入都有錯誤,因為src
目錄中的源根目錄。 我嘗試在 settings.json 中設置 linter 路徑,但是 linter 不起作用
"python.linting.pylintPath": "cd src && pylint"
問題是:如何在 VS Code 中更改 pylint 的源根目錄? 我使用這個擴展https://github.com/DonJayamanne/pythonVSCode
您可以通過在項目根目錄中創建一個包含以下內容的.env
文件來解決此問題:
PYTHONPATH=./src
在您的settings.json
文件中添加這一行(在.vscode
目錄中)。
"python.autoComplete.extraPaths": ["./src"],
PYTHONPATH
是python
的路徑,而不是工作目錄。
更好的方法是自定義Settings.json
和launch.json
,這樣做:
// vi .vscode/Settings.json
{
"python.pythonPath": "venv/bin/python",
"python.linting.pylintEnabled": true,
"python.linting.enabled": true,
"python.formatting.provider": "autopep8"
}
// vi .vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: your project name",
"type": "python",
"request": "launch",
"cwd": "${workspaceRoot}/src",
}
]
}
參考: https ://code.visualstudio.com/docs/editor/debugging#_launch-versus-attach-configurations
在 vs-code 中:文件 - 首選項 - 設置 搜索:Pylint "Pylint: Path" - 添加項目
它對我有用!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.