VS Code - pylint is not running - visual-studio-code

I have a workspace setup in VS Code where I do python development. I have linting enabled, pylint enabled as the provider, and lint on save enabled, but I continue to see no errors in the Problems panel. When I run pylint via the command line in the virtual environment i see a bunch of issues - so I know pylint works. I am also using black formatting(on save) which works without issue. I have tried using both the default pylint path as well as updating it manually to the exact location and still no results. When I look at the Output panel for python it looks like pylint is never even running (i.e. I see the commands for black running there but nothing for pylint).
My pylint version is 2.4.4 and VS Code version 1.46
Any idea how to get this working?

This is due to a bug in the newer version of python extension see here.
For now you can either wait for the fix to arrive, use jedi language server or install previous version of the extension

Add
"python.linting.enabled" : true
"python.linting.lintOnSave" : true
to your settings.json

Uninstall Python Extension
Reinstall Python Extension
And with that there will will be one more extension of "Python Extension" named - "PYLANCE" don't forget to install that too.
Reload VS Code
DONE !!

Related

Disable errors in .pylintrc doesn't work in VS Code

I met strange behavior of pylint in VS Code. '.pylintrc' doesn't recognize after recreating.
My steps:
Install pylint in VS Code
Set pylint as linter using 'Python: Select linter' command
Add '.pylint' with disabling some of warnings:
[MESSAGES CONTROL]
disable=missing-function-docstring,
missing-final-newline,
missing-class-docstring,
missing-module-docstring,
invalid-name,
too-few-public-methods
And it works fine! But then I tried to set pylint configuration in 'pyproject.toml':
[tool.pylint.messages_control]
disable = ["missing-function-docstring",
"missing-final-newline",
"missing-class-docstring",
"missing-module-docstring",
"invalid-name",
"too-few-public-methods"
]
After that exluded warnings shows again.
Ok, I deleted 'pyproject.toml' and return '.pylintrc' - no effect. I tried to select linter again, reopen VS Code, reinstall pylint, but nothing helps.
Version: 1.70.0 (user setup)
Commit: da76f93349a72022ca4670c1b84860304616aaa2
Date: 2022-08-04T04:38:16.462Z
Electron: 18.3.5
Chromium: 100.0.4896.160
Node.js: 16.13.2
V8: 10.0.139.17-electron.0
OS: Windows_NT x64 10.0.19044
pylint version 2.15.0
Two things:
Configuring pylint via pyproject.toml is indeed a hassle, because this specific file only gets respected if pylint is run from precisely that directory. Many IDEs however (Spyder at least, but it seems PyCharm is similar) apparently always run pylint from the respective subdirectory, i.e. from the folder that directly contains the file undergoing linting. Thus, your pyproject.toml isn't respected in these cases. (If you find this behavior weird, you're not the only one, but that's how pylint currently does it.) So this is the underlying reason for the errors in your screenshot. On the other hand, any .pylintrc in the project does indeed get respected even when pylint is run from inside a subdirectory. So for now I would indeed recommend configuring pylint by a .pylintrc in your project and not by pyproject.toml. (I think there is some option whereby one can make .pylintrc just point to the pyproject.toml, which would then hold all the concrete configuration and would be respected even from subdirectories – this would then be the best solution for the time being.)
To resolve your issue that remains with .pylintrc: Tell pylint to show you the path of the configuration file which it uses when it's called. For this, use the command line: cd into the directory in question and run pylint in verbose mode: pylint --verbose. This shows you what config file is being used. (For instance, you might have a long-forgotten pylintrc or .pylintrc sitting around somewhere in your home directory that gets loaded.)
By the way, this trick – using verbose mode to see what configuration file is actually being used – is useful with many tools.

Code-Runner Extension Refuses to Use the Correct Environment

I'm having a bit of trouble getting code-runner to play nice with my conda environments.
Checklist;
The correct python interpreter is selected.
I've explicitly changed the pythonPath and executorMap objects in the settings.json file to the correct environment.
I've tried reinstalling VSCode, Conda and the Code-Runner extension.
I've run a quick script to check which environment is being used and it confirmed that code-runner insists on using the base environment, rather than the one selected, as shown below.
Just to clarify, the code runs perfectly fine, and shows the correct environment selected when I use Ctrl+F5 instead of code-runner (or when I uninstall code-runner and use the normal run feature), but I'd like for it to work with the extension too.
Please help, thanks in advance!

Wrong Python interpreter being used by VS Code

I am on Ubuntu 20.04 and have both Python2 and Python3 installed natively. I have also installed Python through miniforge, a variant of miniconda. In VSCode I have both the MS Python extension and Pylance installed.
I use the miniforge python for my coding. This works perfectly fine in PyCharm.
However in VSCode, when I try to execute the same file I get errors. After investigating it seems that VSCode is picking native Python2 - even though I have the miniforge Python selected. In this picture it can be seen that the status bar at the bottom states Python interpreter selected is Python3. But the output window shows that the python interpreter is Python2.
A more confusing thing is when I use VSCode for Jupyter notebook files then it picks up the interpreter correctly and I have no issues.
I have checked both User and Workspace settings, and they all point to Python3. How can I fix this for standard .py files?
I prefer VSCode to PyCharm, but will need to use PyCharm till this is resolved.
It seems that your system console cannot see python3. You need to put the python3 in the PATH variable, before python2. Like:
PATH=path/to/python3:path/to/python2:$PATH
Also, make sure that the environment containing python3 is activated before command prompt appears. It can be done in bash_profile by adding a line like
conda activate my_env_with_python3
Try changing the settings "Python:Python path", "Python:default interpreter path" and "Python:conda path" also.
I have just bumped into something similar. The Run code option resulted in the file being run with the default interpreter instead of the venv-based one with necessary packages installed.
The fix was simply to use "Run python file" instead:
The run-code behavior must be customizable, something is mentioned e.g. here: Run Code vs Run Python File in Terminal for VSCODE but I didn't bother.

Couldn't start client ESLint message in VS Code

Recently I run into problem with ESlint extension in VS code. When I launch VS code and open up a js file, it popup message "Couldn't start client ESlint". It used to work fine. I tried to re-install eslint, VS code but it didn't help. Here are the versions I used.
VS code: 1.44.0 (user setup)
eslint: v6.8.0
ESLint Extension for VS code: 2.1.2
You need to dig a little bit more to get more details.
A good place to start would be to run the eslint show output command in VSCode. That should be a good starting point.
screenshot of ESLint: Show Output Command
The bottom line is that you need to follow the conventional installation path:
add eslint extension in vscode.
install eslint locally or globally via npm,
run eslint init in your project path and select proper configurations.
restart vscode just to make sure the settings are active.
again, the eslint output console should be a good starting point.
For me, it turns out I had the eslint.runtime and eslint.nodePath settings set to the specified node path on my system, but they were prefixed like this:
~/.nvm/versions/node/v14.17.0/bin/node
Using $HOME instead of ~ didn't solve it either.
I ended up having to specify an absolute path:
/home/<myusername>/.nvm/versions/node/v14.17.0/bin/node

Rust autocompletion not shown for items from the standard library

I can't get working autocompletion on VS Code on Ubuntu 16.04.
I've installed rustup from https://www.rustup.rs/ and installed the "rust-lang.rust" package. This extension installed rustfmt and tried to use both stable and nightly toolchains.
If I type std:: no suggestions are shown. Suggestions show on local mod import but not with the standard library. I tried to reinstall by removing via uninstall.sh and manually removing ~/.multirust and ~/.cargo and then installed again, but nothing changed.
What did I do wrong?
I didn't have the RUST_SRC_PATH variable set. In my VS Code settings, I added
"rust.rustLangSrcPath": "/home/ilya/.rustup/toolchains/**your_toolchain**/lib/rustlib/src/rust/src/"
and it did the job. This option comes from the kalitaalexey.vscode-rust package.