When running ipynbs in VS Code, I've started noticing Pylance warnings on standard library imports. I am using a conda virtual environment, and I believe the warning is related to that. An example using the glob library reads:
"env\Lib\glob.py" is overriding the stdlib "glob" modulePylance(reportShadowedImports)
So far my notebooks run as expected, but I am curious if this warning is indicative of poor layout or is just stating the obvious more of an "FYI you are not using the base install of python".
I have turned off linting and the problem stills persists. And almost nothing returns from my searches of the error "reportShadowedImports".
The reason you find nothing by searching is because this check has just been implemented recently (see Github). I ran into the same problem as you because code.py from Micropython/Circuitpython also overrides the module "code" in stdlib.
The solution is simple, though you then loose out on this specific check. Just add reportShadowedImports to your pyright config. For VS Code, that would be adding it to .vscode/settings.json:
{
"python.languageServer": "Pylance",
[...]
"python.analysis.diagnosticSeverityOverrides": {
"reportShadowedImports": "none"
},
[...]
}
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:
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
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)
I use Tox to run unit tests, with a flake8 command that checks for code formatting errors. Each time I code in PyCharm, I run tox then realise I have a bunch of annoying formatting errors I have to back and manually fix. I would like PyCharm to automatically format the code (according to flake8 google for me each time it auto-saves after I stop typing.
my tox testenv looks like this:
[testenv:flake8]
commands=flake8 <my_code_directory>
deps =
flake8==2.4.1
flake8-import-order==0.11
pep8-naming==0.4.1
[flake8]
max-line-length = 120
import-order-style = google
Is this possible? Do I have to download a specific plugin somewhere? If not with flake8, what about just PEP-8?
Flake8 and import ordering are not auto-fixable in a way that complies with what you're seeing. You can auto-fix pep8 with autopep8.
There are discussions here about implementing this for Flake8 though.
For automatically sorting import statements use isort. Consider using black to auto-format your Python code.
Edit: ruff can replace flake8 and isort and is also much faster because it's based on Rust. It also supports LSP, so PyCharm you should be able to use it from within PyCharm.
The tool you want is probably autopep8. This is especially because the warning codes it uses correspond to the flake8 ones.
For example, if you want to autofix all instances of E701 multiple statements on a single line warning, run the following
for f in `find . -name "*.py"`; do autopep8 --in-place --select=E701 $f; done