My Pylint isn't picking up errors in VSCode.
if I run pylint file.py in the terminal I get the following ouptut:
************* Module file
file.py:38:27: E0001: invalid syntax (<unknown>, line 38) (syntax-error)
so I feel like I can be pretty sure Pylint has installed okay
However, in the Problems tab on VS Code, all I can see is "No problems have been found in the workspace so far". I've intentionally made a number of different errors to test it and none of them are being found by Pylint.
In settings, linting is definitely enabled and set to run on save. If I run CTRL + shift + P and then choose "Run Linting" I still don't get any problems found.
My settings.json are:
{
"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\wsl.exe",
"git.confirmSync": false,
"python.linting.enabled": true,
"window.zoomLevel": 0,
"python.pythonPath": "C:\\Users\\becky\\anaconda3\\python.exe",
"files.autoSave": "off",
"terminal.integrated.automationShell.linux": "",
"python.linting.pylintEnabled": true,
"python.linting.pylintUseMinimalCheckers": false,
"python.linting.pylintArgs": ["--load-plugins", "pylint_django"],
"terminal.integrated.env.linux": {
},
"python.linting.pylintCategorySeverity.convention": "Hint",
"terminal.integrated.automationShell.windows": ""
}
I'm really lost here, I'd really appreciate any help with this because I'm not too sure where else to look!
Thanks!
Related
I have Visual Studio Code installed with the Python extension. When I try to open a .py or .ipynb file from the Windows File Explorer with VSCode, nothing opens and I get the windows "ding" sound instead (the same sound you get when a popup prevents you from interacting with other apps until you dismiss the popup). I tried user settings with and without file.associations, but either case did not work. Everything seems to work fine when from VSCode I choose File>>Open Folder and then browse to the .py or .ipynb file. Any idea why this is happening?
{
"python.dataScience.sendSelectionToInteractiveWindow": true,
"python.testing.unittestEnabled": true,
"editor.renderWhitespace": "selection",
"editor.renderControlCharacters": false,
"window.zoomLevel": -1,
"workbench.colorTheme": "Visual Studio Dark",
"python.linting.pycodestyleCategorySeverity.E": "Information",
"python.linting.pycodestyleCategorySeverity.W": "Information",
"editor.minimap.showSlider": "always",
"editor.minimap.maxColumn": 100,
"python.linting.pycodestyleEnabled": true,
"editor.accessibilitySupport": "off",
"[xml]": {},
"python.dataScience.askForKernelRestart": false,
"git.enableSmartCommit": true,
"[jsonc]": {},
"editor.minimap.size": "fill",
"editor.tabSize": 2,
"python.dataScience.textOutputLimit": 0,
"files.associations": {
"*.py": "python",
"*.ipynb": "python",
"*.pyt": "python"
},
"python.pythonPath": "c:\\my\\env\\Python.exe",
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.linting.enabled": true,
}
I don't believe that shell file associations are set up with VS Code by default. files.associations setting is just to tie file extensions to the type of code inside visual studio code itself. If you right-click on a .py file do you see an option Open With=>Visual Studio Code? That option should be available to open it in VS Code.
If you want that to be default you can right click it in the shell and pick Open With=>Choose another app to select VSCode as the default app to open that item with.
I can't seem to get my settings.json file to influence how python is invoked in VSCode when selecting "Run Code" (default hot key Ctrl + Alt + N), my user settings.json is as follows:
{
"python.pythonPath": "/usr/bin/python3",
"editor.suggestSelection": "first",
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
"python.jediEnabled": true,
"editor.minimap.enabled": true,
"editor.multiCursorModifier": "ctrlCmd",
"workbench.tree.indent": 24,
"workbench.startupEditor": "untitled",
"workbench.settings.editor": "json",
"workbench.settings.openDefaultKeybindings": false,
"workbench.settings.openDefaultSettings": true,
"workbench.settings.useSplitJSON": false,
"explorer.confirmDragAndDrop": false,
"python.linting.enabled": true,
"python.languageServer": "Jedi",
}
yet when I run my python file, not debug it, it is showing:
[Running] python -u "path/to/file.py"
when I am expecting (as I set python.pythonPath in settings.json):
[Running] /usr/bin/python3 -u "path/to/file.py"
Why is my settings.json file key python.pythonPath having no effect on how my code is invoked?
Among other important reasons, my python code doesn't even run as python invokes python 2 on my machine when my code is written in python 3.
VSCode version:
Version: 1.47.3
Commit: 91899dcef7b8110878ea59626991a18c8a6a1b3e
Date: 2020-07-23T15:51:39.791Z (1 mo ago)
Electron: 7.3.2
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Linux x64 4.15.0-112-generic
From vscode-python-DeprecatePythonPath, python.pythonPath setting is being removed from all 3 scopes - User, workspace, workspace folder. The path to the workspace interpreter will now be stored in VS Code’s persistent storage instead of the settings.json file. That's why your setting has no effect on code execution path. You can change the value stored in workspace settings using Python: Select Interpreter command, or add the setting in User settings.json:
"python.defaultInterpreterPath":
I am running a Django application in VSCode, using pylint, and the relative imports errors are not displaying. They were before I installed a newer version of VSCode.
I have tried changing user settings and also workspace settings, but still can't get the errors to show.
User Settings
{
"window.zoomLevel": 1,
"explorer.confirmDelete": false,
"workbench.startupEditor": "newUntitledFile",
"window.menuBarVisibility": "default",
"explorer.confirmDragAndDrop": false,
"workbench.colorTheme": "Visual Studio Dark",
"update.enableWindowsBackgroundUpdates": false,
"update.channel": "none",
"php.validate.run": "onSave",
}
Workspace settings
{
"python.linting.enabled": true,
"python.linting.pep8Enabled": false,
"python.linting.pylintArgs": ["--load-plugins", "pylint_django"],
"python.linting.pylintEnabled": true,
"python.pythonPath": "/home/justin/anaconda3/bin/python",
"python.linting.pylintPath": "/home/justin/anaconda3/bin/pylint"
}
At the top of one of my functions, a couple of different relative imports. Which one is right or wrong, VSCode should show me. Both imports are in the same project directory in Django, therefore import should be a single '.' I believe.
from .performance import get_perf_dates, get_perf_data
from ..models import DistributionList, Legend
When I am running via shell a pylint:
$ pylint decorator.py
No config file found, using default configuration
************* Module decorator
C: 7, 0: Unnecessary parens after 'print' keyword (superfluous-parens)
C: 15, 0: Unnecessary parens after 'print' keyword (superfluous-parens)
C: 1, 0: Missing module docstring (missing-docstring)
C: 4, 0: Missing function docstring (missing-docstring)
C: 6, 4: Missing function docstring (missing-docstring)
C: 14, 0: Missing function docstring (missing-docstring)
However, as it can be seen below, these warning do not come up in VSCode
... despite the fact that some basic checking is indeed performed as it shown in the next picture where I have removed a blank line:
Assuming you have configured Python's Extension correctly and you have Pylint installed,
VSCode's Python Extension will do minimal checking by default if you do not provide a Pylint configuration option.
Simply enter "python.linting.pylintUseMinimalCheckers": false, into your .vscode/settings.json to force this off.
This is how mine looks:
{
"autoDocstring.docstringFormat": "numpy",
"editor.minimap.enabled": false,
"editor.selectionClipboard": false,
"python.pythonPath": "/home/jim/anaconda3/envs/dipoleDisplay",
"window.zoomLevel": 0,
"terminal.integrated.rendererType": "dom",
"python.linting.pylintUseMinimalCheckers": false,
}
I had a similar problem where flake8 worked in VSCode but pylint didn't. Here are all the steps I had to check for pylint to start working:
Your .vscode\settings.json file enables linting by pylint
(this can be hand edited or by running these command palette commands: Python: Enable Linting and Python: Select Linter)
"python.linting.enabled": true
"python.linting.pylintEnabled": true
from the command line (while in virtual environment) confirming that pylint and pylint-django are installed.
pip show pylint
pip show pylint-django
Add a .pylintrc file to your root directory that includes these lines.
[MASTER]
load-plugins=pylint_django
(NOTE: you can replace this pylintrc file with the following line in settings.json.)
"python.linting.pylintArgs": ["--load-plugins", "pylint_django"]
For more info about using pylint in VSCode, see https://code.visualstudio.com/docs/python/linting#_pylint
For more info about the pylintrc file, see https://docs.pylint.org/en/1.6.0/run.html#command-line-options
I'm add json to my vscode project folder settings:
{
...
"pylint.path": [
"/home/username/.local/bin/pylint"
],
"pylint.args": [
"--rcfile=api/.pylintrc"
],
...
}
It working for me. My python files and .pylintrc file placed in ./api/ folder, which is subfolder of my project's root.
Using Python3 with Visual Studio Code (Python extension installed) within Ubuntu 16.04.
I have some basic script written:
def mainMethod():
what()
#connectToDevice()
if __name__ == "__main__":
mainMethod()
When I debug this in Visual Studio Code by hitting F5 I can't see any output with the error in Debug Console:
Traceback (most recent call last):
File "main.py", line 9, in
mainMethod()
File "main.py", line 5, in mainMethod
what()
NameError: name 'what' is not defined
If I run python3 main.py in console the output appears.
How can I see those errors in VSCode and avoid switching back and forth between it and console?
I still can't see the output in Debug Console all the time but I can see it in the Integrated Terminal by setting this option in launch.json file of VSCode. The file looks like this:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python virtual env",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"console": "integratedTerminal",
"program": "${workspaceRoot}/main.py",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
],
"pythonPath": "${workspaceRoot}/env/bin/python3"
}
]
}
The core line is "console": "integratedTerminal". Also please note that this configuration is using the interpreter from the Virtual Environment folder and the file which starts is always main.py instead of the default option which runs the file from the active editor.
EDIT: it seems that later versions solved this problem so above workaround doesn't apply anymore
In the Feb 2018 update to VS Code this issue appears to be entirely resolved. So you don't need to make any changes to the default config, becuase the integrated debug terminal is finally printing errors when they occur.
A slightly better way, for me, is to just add "console": "externalTerminal" rather than internalTerminal. That opens a new terminal when debugging, but it's a clearer one and it closes almost automatically.
I have a similar problem in my case was the Python Linter didn't show the errors.
My mistake was, that I open the VS Code when a VirtualEnv was active. Whit the command
code .
To fixed I close VS Code, delete de .vs folder, deactivate de VirtualEnv, then open VS Code and then open VirtualEnv.
And done!, problem solve. Other solution in my case would be install the linter (if I remember right, pylint is the default linter for vscode).