Pylint 在 Visual Studio 代码中不起作用 [英] Pylint does not work in visual studio code

查看:79
本文介绍了Pylint 在 Visual Studio 代码中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Mac 上使用 Visual Studio 代码作为 python IDE,一切正常.但几周前我开始使用 Windows.突然间我无法在我在 Mac 上启动的项目中使用 pylint.

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.

我有

  • 显式激活 pylintEnabled 选项 (=True)
  • 设置了 pylint.exe 的完整路径(c:\Anaconda 3...")
  • pylintrc 文件,带有初始钩子,将项目添加到根目录中的 pythonpath(由 pylint 使用 --generate-rcfile 生成).
  • 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.

使用完全相同的参数,在 Linux (Ubuntu 16.10) 和 Mac 上一切正常.并且不适用于两台 Windows 机器.看来pylint只是不运行.

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.

我哪里做错了?

更新:

我发现 pylint 出现了 UnicodeDecodingError:

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

更新 2

我使用自动生成的 pylintrc 文件收到此错误.没有这个文件,一切都正常(除了我无法使某些通知静音,使用 pylint_flask 插件并进行初始挂钩).

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).

更新 3:正确的解决方案(感谢 Elijah W. Gagne 的评论)这工作正常:

pylint --generate-rcfile | out-file -encoding utf8 .pylintrc

推荐答案

我在 Windows 中遇到了同样的问题,我通过以下方式获得了 pylintrc 文件:

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

pylint --generate-rcfile > ~/.pylintrc

虽然我用notepad++打开它,但编码不是utf8,我把它改成utf8,然后就可以了.

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

这篇关于Pylint 在 Visual Studio 代码中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆