Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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,

like image 503
rix Avatar asked Aug 14 '14 21:08

rix


People also ask

How do I enable Linter sublime?

You can quickly toggle a linter on or off. To do so: Bring up the Command Palette ( cmd+shift+p on Mac OS X, ctrl+shift+p on Linux/Windows) and type toggle , disable , or enable according to what you want to view all linters, only enabled linters, or only disabled linters.

What is sublime Linter?

Sublime Linter is the package of Sublime Text that helps you to perform linting in Sublime. It helps in creating files in different modes for the manipulation of code base. It is not an in built package and you need to install it manually.

What is sublime text3?

Sublime Text 3 (ST3) is a lightweight, cross-platform code editor known for its speed, ease of use, and strong community support. It's an incredible editor right out of the box, but the real power comes from the ability to enhance its functionality using Package Control and creating custom settings.


2 Answers

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.

like image 107
architux Avatar answered Nov 16 '22 15:11

architux


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

"settings":
{
    "SublimeLinter.linters.flake8.python": "/path/to/venv/bin/python"
}
like image 5
yan Avatar answered Nov 16 '22 15:11

yan