VS Code Python Intellisense and pylint not working properly - python

I just installed VS Code on my Macbook, and set out to test a few of its features. I installed the Python extension, pylint, selected the Python interpreter...followed the docs to the letter. Oddly, the Intellisense feature doesn't seem to be working, and pylint looks a bit odd. I expect squiggly red error lines, and a lightbulb next to the line with np.array suggesting that I import numpy. Instead I have double red underlines and no lightbulb. See image 1. It also only lints when I save the file. The error when I hover the np line is "undefined variable np." So it seems like it's linting, but not doing intellisense.
Similarly, I don't have any code snippets; when I type if and then ^-Space for the drop-down, there aren't any snippets.
I have anaconda installed, but it doesn't make any difference which Python interpreter I use.
Any suggestions? Thanks!
Settings.json file:
{
"python.linting.pylintEnabled": true,
"python.linting.enabled": true,
"python.pythonPath": "/usr/bin/python3" }
VS Code Info:
Version: 1.52.1
Commit: ea3859d4ba2f3e577a159bc91e3074c5d85c0523
Date: 2020-12-16T16:30:02.420Z (1 mo ago)
Electron: 9.3.5
Chrome: 83.0.4103.122
Node.js: 12.14.1
V8: 8.3.110.13-electron.0
OS: Darwin x64 19.6.0

According to the information you provided, I reproduced this problem, please refer to the following method:
The reason for the double horizontal line instead of the wavy line shown in the code is the use of color themes.
(Change theme: F1, Preferences: Color Theme)
Please make sure that the module "pylint" has been installed in your currently selected Python environment. (Install: pip install pylint; check: pip show pylint)
before:
after:

Related

Pylint considers "timeout-methods" option as unrecognised

Versions:
Python: 3.10.4
Pylint: 2.15.3
Visual Studio Code: 1.72.2
The .pylintrc file was generated using
pylint --generate-rcfile
command.
It has the following option configured:
[METHOD_ARGS]
# List of qualified names (i.e., library.method) which require a timeout
# parameter e.g. 'requests.api.get,requests.api.post'
timeout-methods=requests.api.delete,requests.api.get,requests.api.head,requests.api.options,requests.api.patch,requests.api.post,requests.api.put,requests.api.request
However I see an error which sounds:
Unrecognized option found: timeout-methods Pylint(E0015:unrecognized-option)
The documentation states that option timeout-methods is supported: https://pylint.pycqa.org/en/latest/user_guide/configuration/all-options.html#timeout-methods.
So I am lost why do I have that error displayed by pylint in visual studio code.
As the comments under the original code showed, the pylint version bundled in the VS Code extension and the one that was used to generate the .pylintrc file differ.
Normally, the VS Code Pylint extension should use the pylint version installed in the Python environment that you configured to use for your project, and only falls back to the bundled version if no other pylint version was found. See also the extension docs for details.
Check the following:
Make sure that you configured the correct Python environment for your project. See Select a Python interpreter in the docs.
Make sure that you have installed pylint in the Python environment you have configured for your project, and are not accidentally using a pylint installation from your global Python environment. After configuring the Python interpreter (see step 1), once you open a new terminal in VS Code this environment should be activated by default. Run pip list | grep pylint (macOS/Linux) or pip list | findstr pylint (Windows) to check if pylint is installed.
If both 1 & 2 are fulfilled and you still have problems, check if pylint.importStrategy is maybe set to useBundled in your VS Code settings.json, and remove it or set it to fromEnvironment.
pylint 2.15 take this option into account correctly. But it was released only 2 month ago. Your error must come from the pylint version included in visual studio code that might lag a little behind and do not handle it yet.

VS Code pycodestyle not recognizing errors

I'm using Atom as code editor on Ubuntu 20.04 and I currently try whether VS Code might be a replacement for my purposes.
One thing that annoys me a lot with VS code is that linting doesn't work as expected - and as I was used to with Atom. The below will be specifically for pycodestyle.
One issue is that quite a lot of warnings are not reported at all, such as e225 or e303.
Another is that too long lines are ignored at all once I increase the 80 character limit to 120 by adding the args "--line-length" and "120".
How can I fix these issues?
The functions you mentioned are the requirements of "flake8". You need to install falke8 and yapf first by the following code :
pip install flake8
pip install yapf
Then we configure linting in vscode and add the following contents to setting.json(ctrl+shift+P and choose "preferences:open settings(json)"):
"python.linting.flake8Enabled": true,
"python.formatting.provider": "yapf",
"python.linting.flake8Args": [
"--max-line-length=120"
],
"python.linting.pylintEnabled": false
In this way, the format recognition of flake8 is started, and your second problem can also be effectively solved. I made a simple reproduction:

VSCode: Linting not working on Python 2.7

System: Win x64 10.0.18363
VSCode: 1.43.2
Python: 2.7.10 32-bit
My linter just stopped working on VSCode around the time I installed flake8. I have no clue what is wrong because the linter is running it just does not print any problems. Everytime I run the linter it shows me:
C:\Python27\python.exe -m pylint --disable=all --enable=F,unreachable,duplicate-key,unnecessary-semicolon,global-variable-not-assigned,unused-variable,unused-wildcard-import,binary-op-exception,bad-format-string,anomalous-backslash-in-string,bad-open-mode,E0001,E0011,E0012,E0100,E0101,E0102,E0103,E0104,E0105,E0107,E0108,E0110,E0111,E0112,E0113,E0114,E0115,E0116,E0117,E0118,E0202,E0203,E0211,E0213,E0236,E0237,E0238,E0239,E0240,E0241,E0301,E0302,E0303,E0401,E0402,E0601,E0602,E0603,E0604,E0611,E0632,E0633,E0701,E0702,E0703,E0704,E0710,E0711,E0712,E1003,E1101,E1102,E1111,E1120,E1121,E1123,E1124,E1125,E1126,E1127,E1128,E1129,E1130,E1131,E1132,E1133,E1134,E1135,E1136,E1137,E1138,E1139,E1200,E1201,E1205,E1206,E1300,E1301,E1302,E1303,E1304,E1305,E1306,E1310,E1700,E1701 --msg-template='{line},{column},{category},{symbol}:{msg}' --reports=n --output-format=text "c:\ Correct Path (removed for privacy reasons)"
cwd: c:\ Correct Path (removed for privacy reasons)
(first 2 lines printed again)
##########Linting Output - pylint##########
Nothing ever gets outputted. When I switch to Python 3.8 it works perfectly and shows me all the errors as it should. It has the exact same output with just different path for Python 3.8. My settings.json include the following:
"python.pythonPath": "C:\\Python27\\python.exe",
"python.linting.pylintEnabled": true,
"python.linting.pylintUseMinimalCheckers": true,
"python.linting.enabled": true,
"python.linting.mypyEnabled": false,
I tried every settings I could, but there is no difference. I tried over 5 linters and they all do the same thing. I just get no output whatsoever on my console anymore and I don't know why. It was working before so I know it is not any path issues.
The only hint I have, is that if I go to developer tools, there is an error on line 173 of console.ts
Error Python Extension: 2020-03-29 21:56:02: stderr jediProxy Error (stderr) completion.py:586: DeprecationWarning: Deprecated since version 0.16.0. Use Script(...).get_names instead.
jedi.api.names(
for the code:
(console as any)[entry.severity].apply(console, consoleArgs);
// underlined red is -> 'apply(console, consoleArgs);'
I tried googling this error, but I was not getting anything that was on my particular problem. Any help would be great.
EDIT
I found a temporary solution after a few hours. It is to simply turn off Jedi. You have to go to settings and find Python: Jedi Enabled and turn it off. I say it is temporary as I would prefer to have Jedi on so I will not answer my question just yet. This seems like a new bug so I hope this helps others.
It should be a Jedi version issue, I solve it by specifying the version.
pip install jedi==0.15.2

lost python syntax highlight in vscode

The syntax highlighting has almost been lost in vscode.
enter image description here
My vscode version is:
Version: 1.40.1 (system setup)
Commit: 8795a9889db74563ddd43eb0a897a2384129a619
Date: 2019-11-13T16:49:35.976Z
Electron: 6.1.2
Chrome: 76.0.3809.146
Node.js: 12.4.0
V8: 7.6.303.31-electron.0
OS: Windows_NT x64 10.0.18362
I have installed all the extensions in the Python Extension Pack (1.6.0).
Operating system: Windows 10
What should I do to restore the syntax highlighting?
Thanks
Two things to check. One, make sure you have a colour theme chosen which highlights what you want highlighted. Two, make sure that your file has a its language mode set to "Python".
Otherwise VS Code provides Python syntax highlighting out of the box without any extensions.

VS Code shows an error message at print statement in python 2.7

I use VS Code Version 1.19.3 with Python 2.7 on Windows.
Recently pylint (code analyzer) shown an error message
"E1601:print statement used"
But I don't know why! Can someone help me?
The print statement is correct as per my knowledge!
Is it a bug or a feature is missing?
Greetings niesel
The warning originates from Pylint, which is a very helpful tool for a dynamic language with loose syntax like Python. Since you are programming in Python 2.x where print is perfectly valid, I suggest you put a file in the root of your repo named .pylintrc and use it to configure Pylint.
To disable the print warning and leave everything else to the default, enter these two lines in your .pylintrc file:
[MESSAGES CONTROL]
disable=print-statement
You will also need to tell Visual Studio Code to use your configuration file by opening your workspace or user settings and add this:
{
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.linting.pylintArgs": [
"--rcfile=/path/to/.pylintrc"
]
}
More options
To get a good idea of available configuration options open a terminal/prompt and run this command to generate a sample configuration file:
pylint --generate-rcfile > sample_pylintrc
The problem is, that changing from print statement to print function doesn't help much. So it seems, that it is some bug in VS Code Python module (2018.1 (01 Feb 2018)), as after this update I've found the same problem in my VS Code within my old projects
I've found reffered bug on their github
PS: vscode-python has changed pylint options since 2018.1. In order to return old behavior you may disable python.linting.pylintUseMinimalCheckers option for the workspace or for the userspace.
it's not an error per-se, it's just PyLint complaining about those legacy statements. PyLint will also complain about missing spaces before commas, those kind of style errors.
PyLint is there to warn you about possible problems. Your code will break when running python 3, so it warns you before it happens.
Note that print is a statement in python 2.x (which explains the message), and became a function in python 3.x.
Fix it by changing to:
print("test")
Since it's not a tuple, it works fine and does exactly the same for all versions of python, and PyLint will stop complaining.
you can also get rid of PyLint altogether: Windows 10 - Visual Studio Code - removing pylint (not sure if it's a good idea)

Categories

Resources