简体   繁体   中英

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

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.

By now I've solved the problem by just using a copy of my pylintrc file from mac. The problem - as far as I understand it - comes from the Windows Powershell. When I do

pylint --generate-rcfile > pylintrc

it creates a file with cp-1251 encoding.

The solution is to copy the data and paste it into an IDE/text editor to save it as utf-8 file. Or simply (like I did) copy it from another system or from the web.

What I observe, with my pylint 2.4.4 and VS Code 1.43.0 at least, is that pylint is irrespective to its' ~/.pylintrc file encoding. I tried it with quite a few encodings (far not only UTF8-BOM, UTF8-noBOM, but few others) - none of them caused it to fail.

The problem, discussed here, in my case was caused that I did not escaped slashes in ~/.pylintrc file [MASTER] section, when defining an init_hook it it.

I had:

[MASTER]

# other statements
...


init-hook="import sys; sys.path.append('C:\Users\<username>\Documents\<project>')"

and that caused the problem exactly like discussed here.

Once I added a r modifier before the path, like this:

[MASTER]

# other statements
...

init-hook="import sys; sys.path.append(r'C:\Users\<username>\Documents\<project>')"

it fixed the problem right away.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM