Specify which python version pylint should evaluate for

前端 未结 7 1343
孤城傲影
孤城傲影 2020-12-18 17:58

I\'m using Sublime Text 3 With Pylinter to run pylint on my files.

However, on the same machine, I work on files for both python 2, and python 3 project

相关标签:
7条回答
  • 2020-12-18 18:39

    You can override on a per-project level in Sublime Text by changing the pylint executable setting in Project->Edit Project to include:

    "settings":
    {
        "SublimeLinter.linters.pylint.executable": ["py", "-3.4", "-m", "pylint"],
    }
    

    substituting 3.4 for your preferred flavour

    0 讨论(0)
  • 2020-12-18 18:41

    You should have two pylint installations, say pylint2 and pylint3, then write a wrapper script that will subprocess the desired one.

    0 讨论(0)
  • 2020-12-18 18:42

    This is good, but I think the simplest thing is just to use virtualenv, and install pylint in each virtualenv. The correct pylint and python interpreter will be used.

    0 讨论(0)
  • 2020-12-18 18:43

    You can install pylint3 which will evaluate for python 3.0, and pylint which will evaluate the code as python 2.7 by default.

    0 讨论(0)
  • 2020-12-18 18:47

    You can try python2 -m pylint ... and python3 -m pylint .... That ensures that you use the right version.

    0 讨论(0)
  • 2020-12-18 18:47

    Expanding on @sthenault's answer and borrowing heavily from @simon's to a very similar question on askubuntu, the solution is to write a wrapper script around pylint that executes it with the appropriate version of the Python interpreter. Drop the following into a script called mypylint (or whatever) somewhere in your $PATH:

    #! /usr/bin/env bash
    
    python_interpreter="python${1}"
    pylint_args="-f colorized ${@:2}"
    pylint_import=$(cat << PYTHON
    import sys
    import pkg_resources
    
    __requires__ = "pylint"
    sys.exit(
        pkg_resources.load_entry_point("pylint", "console_scripts", "pylint")()
    )
    PYTHON
    )
    
    $python_interpreter -c "$pylint_import" $pylint_args
    

    Then, execute it like so: mypylint 2|3 PYLINT_ARGS. For instance:

    mypylint 2 -f colorized module.py
    

    I'm not sure how you can tie that into sublime-text, but it more generally answers the question of parallel versions of pylint. I also bundled the above solution into a gist.

    0 讨论(0)
提交回复
热议问题