[英]How to setup working directory in VS Code for pylint?
I have a project with that structure:我有一个具有这种结构的项目:
├── .git
├── .gitignore
├── README.md
├── requirements.txt
└── src
Pylint by default running from project root and I have error on all my imports, because source root in src
directory. Pylint 默认从项目根目录运行,我的所有导入都有错误,因为
src
目录中的源根目录。 I try to setup the linter path in settings.json, but then linter don't work我尝试在 settings.json 中设置 linter 路径,但是 linter 不起作用
"python.linting.pylintPath": "cd src && pylint"
Question is: how to change the source root for pylint in VS Code?问题是:如何在 VS Code 中更改 pylint 的源根目录? I use this extension https://github.com/DonJayamanne/pythonVSCode
我使用这个扩展https://github.com/DonJayamanne/pythonVSCode
您可以通过在项目根目录中创建一个包含以下内容的.env
文件来解决此问题:
PYTHONPATH=./src
在您的settings.json
文件中添加这一行(在.vscode
目录中)。
"python.autoComplete.extraPaths": ["./src"],
The PYTHONPATH
is the path to python
, not the working directory . PYTHONPATH
是python
的路径,而不是工作目录。
The better way is to customize Settings.json
and launch.json
, do like this:更好的方法是自定义
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",
}
]
}
refer: https://code.visualstudio.com/docs/editor/debugging#_launch-versus-attach-configurations参考: https ://code.visualstudio.com/docs/editor/debugging#_launch-versus-attach-configurations
In vs-code: File - Preferences - Settings Search for: Pylint "Pylint: Path" - Add item在 vs-code 中:文件 - 首选项 - 设置 搜索:Pylint "Pylint: Path" - 添加项目
It work for me!它对我有用!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.