Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pylint does not work in visual studio code

I use Visual Studio code as python IDE on Mac, and everything works fine for me. But a couple of weeks ago I've started to use Windows. And suddenly I'm unable to use pylint in the project I've started on Mac.

I have

  • explicitly activated pylintEnabled option (=True)
  • full path to pylint.exe is set ("c:\Anaconda 3...")
  • pylintrc file with initial hook adding project to pythonpath (generated by pylint using --generate-rcfile) in the root directory.

With the very same parameters, everything works fine both on Linux (Ubuntu 16.10) and Mac. And does not work on two Windows machines. It seems that the pylint just does not run.

Where did I go wrong?

Update:

I've found out that pylint is getting the UnicodeDecodingError:

##########Linting Output - pylint##########

Traceback (most recent call last):
  File "C:\Program Files\Anaconda3\Scripts\pylint-script.py", line 5, in <module>
    sys.exit(pylint.run_pylint())
  File "C:\Program Files\Anaconda3\lib\site-packages\pylint\__init__.py", line 13, in run_pylint
    Run(sys.argv[1:])
  File "C:\Program Files\Anaconda3\lib\site-packages\pylint\lint.py", line 1264, in __init__
    linter.read_config_file()
  File "C:\Program Files\Anaconda3\lib\site-packages\pylint\config.py", line 627, in read_config_file
    parser.readfp(fp)
  File "C:\Program Files\Anaconda3\lib\configparser.py", line 760, in readfp
    self.read_file(fp, source=filename)
  File "C:\Program Files\Anaconda3\lib\configparser.py", line 715, in read_file
    self._read(f, source)
  File "C:\Program Files\Anaconda3\lib\configparser.py", line 1012, in _read
    for lineno, line in enumerate(fp, start=1):
  File "C:\Program Files\Anaconda3\lib\codecs.py", line 321, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
  File "C:\Program Files\Anaconda3\lib\encodings\utf_8_sig.py", line 69, in _buffer_decode
    return codecs.utf_8_decode(input, errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

Update 2

I'm getting this error using pylintrc file generated automatically. Without this file, everything works fine (except the fact that I can not silence some of the notification, use pylint_flask plugin and make an initial hook).

Update 3: the propper solution (thanks to the comment of Elijah W. Gagne) This works fine:

pylint --generate-rcfile | out-file -encoding utf8 .pylintrc
like image 259
Mikhail Elizarev Avatar asked May 04 '17 12:05

Mikhail Elizarev


People also ask

How do I fix pylint import error in VSCode?

To solve unresolved import error in Python, set your Python path in your workspace settings. If you are working with Visual Studio Code and import any library, you will face this error: “unresolved import”. Then reload the VSCode, and it will fix that error.

How do I fix Visual Studio Code lint issues?

In your code editor, open the JavaScript file you created earlier. All the broken rules will be indicated. If you have the ESLint extension installed you can use CTRL+SHIFT+P to open the Command Palette. Then search for ESLint: Fix all auto-fixable Problems and press ENTER (or RETURN ).

How do I know if pylint is installed?

First, to check the version of Pylint you're running, run the following command: pylint --version.


1 Answers

I have the same issue in Windows, and I get pylintrc file by:

pylint --generate-rcfile > ~/.pylintrc

While I use notepad++ to open it, the encoding is not utf8, and I change it to utf8, then it works.

like image 163
Yuan Wenjin Avatar answered Sep 18 '22 22:09

Yuan Wenjin