解决sublime使用pylint插件时对django的支持问题

Sublime是我最爱的写代码神器。最近看网上配置sublime为python IDE的文章时,看到很多人推荐使用Pylinter这个插件。仔细研究了一番,这个插件主要是用来检查代码格式的,从而规范化python程序员的编码规范。


但是由于我经常开发的项目是Django,而Django各种ORM把pylint搞得是晕头转向。比如,经常会出现这样一个错误:


Class 'xxx' has no 'objects' member

这个其实就是pylint对Django支持不好的原因。看StackOverFlow大神说需要使用一个“更懂Django”的插件,叫做pylint-django

Ubuntu使用如下命令安装:

sudo pip install pylint-django

然后使用的时候这么使用,在命令行

pylint -E --load-plugins=pylint_django xxx.py

-E是只输出错误信息的意思

解决sublime使用pylint插件时对django的支持问题_第1张图片

可以看到还是有效果的。加了pylint_django的插件以后就不输出错误。但是当在sublime pylint中配置load_plugins时,就成了这样:

解决sublime使用pylint插件时对django的支持问题_第2张图片

出现pylint_plugin_utils.NoSuchChecker错误。。

好吧,根据逐一排查,最终定位到原来问题的根源在于/usr/local/lib/python2.7/dist-packages/pylint_plugin_utils/__init__.py文件中的一个if判断句

临时解决办法:

把__init__.py文件中的get_checker函数中的

if isinstance(checker, checker_class):

替换为

if checker.__class__.__name__ == checker_class.__name__:


 问题解决。。。 
  

附上我的Sublime的Pylinter插件的User.settings

{
    // When versbose is 'true', various messages will be written to the console.
    // values: true or false
    "verbose": false,
    // The full path to the Python executable you want to
    // run Pylint with or simply use 'python'.
    "python_bin": "python",
    // The following paths will be added Pylint's Python path
    "python_path": [
        "/usr/bin/python",
        ],
    // Optionally set the working directory
    "working_dir": null,
    // Full path to the lint.py module in the pylint package
    "pylint_path": "/usr/local/lib/python2.7/dist-packages/pylint/lint.py",
    // Optional full path to a Pylint configuration file
    "pylint_rc": "/home/myusername/myproject/pylint.rc",
    // Set to true to automtically run Pylint on save
    "run_on_save": true,
    // Set to true to use graphical error icons
    "use_icons": true,
    "disable_outline": false,
    // Status messages stay as long as cursor is on an error line
    "message_stay": false,
    // Ignore Pylint error types. Possible values:
    // "R" : Refactor for a "good practice" metric violation
    // "C" : Convention for coding standard violation
    // "W" : Warning for stylistic problems, or minor programming issues
    // "E" : Error for important programming issues (i.e. most probably bug)
    // "F" : Fatal for errors which prevented further processing
    "ignore": ["C", "R",],
    // a list of strings of individual errors to disable, ex: ["C0301"]
    "disable": ["W0702",],
    "plugins": ["pylint_django",],
}


你可能感兴趣的:(python开发遇到的那些坑)