简体   繁体   中英

Is this possible > Sublime3 + a python linter + virtualenv?

I've read a lot of conflicting SO posts, gone through all the relevant github issues I could find, and tried a myriad of config options in various sublime config files before finally giving up and resorting to this plea for help.

It's as the title states - I'd like to use sublime3 + sublime linter + something like pylint to lint my Python code using the Python installed in the specific project virtual environment. I'm not sure of the exact toolchain but as long as it works that's good enough for me.

Please, does anyone know if it's possible - and more importantly how to actually do it?

Thanks in advance,

Update, now sublime linter recommends updating per project settings as follows:

"settings":
{
    "SublimeLinter.linters.flake8.python": "/path/to/venv/bin/python"
}

There is an option to plug flake8 to SublimeLinter with custom virtualenv on per project basis in Sublime Text 3.

You should install flake8 to your virtualenv using pip install flake8 , but be careful no to include flake8 and its dependencies in your requirements.txt .

Then you should edit your SublimeText project settings file and paste the SublimeLinter section there with full path to the Python binary for your particular project's virtualenv:

{
    "settings": {
        "SublimeLinter": {
            "linters": {
                "flake8": {
                    "python": "/path/to/virtualenv_folder/bin/python"
                },
            }
        }
    }
}

Or you may use the one shortened property SublimeLinter.linters.flake8.python as it's been mentioned in the other answer .

So every time SublimeLinter executes in each *.py file being opened from the project, flake8 will be executed from that custom Python virtualenv binary.

Check out SublimePythonIDE (available on Package Control). I believe it uses Pyflakes to lint your code by default.

The documentation also shows you how to set it to use the interpreter in a virtual environment. I don't think it will actively lint your code with virtual environment, but you will have access to stuff like autocomplete, jump-to-definition, view documentation, etc.

In your project settings:

{
    "folders": [
        {
           "path": "XYZ"
        },
        {
            "path": "ABC"
        }
    ],
    "settings": {
        "python_interpreter": "/path/to/some/virtualenv/bin/python"
    }
}

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