简体   繁体   English

这可能> Sublime3 + python linter + virtualenv?

[英]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.我已经阅读了很多相互矛盾的 SO 帖子,浏览了我能找到的所有相关的 github 问题,并在最终放弃并求助于这个请求帮助之前在各种 sublime 配置文件中尝试了无数的配置选项。

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.正如标题所述 - 我想使用 sublime3 + sublime linter + pylint 之类的东西来使用安装在特定项目虚拟环境中的 Python 来整理我的 Python 代码。 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:更新,现在 sublime linter 建议按如下方式更新每个项目设置:

"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.在 Sublime Text 3 中,有一个选项可以将flake8插入带有自定义 virtualenv 的 SublimeLinter。

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 .您应该使用pip install flake8flake8安装到您的 virtualenv 中,但请注意不要在您的requirements.txt包含flake8及其依赖项。

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:然后你应该编辑你的 SublimeText 项目设置文件并将 SublimeLinter 部分粘贴到那里,其中包含特定项目 virtualenv 的 Python 二进制文件的完整路径:

{
    "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 .或者您可以使用一个缩短的属性SublimeLinter.linters.flake8.python因为它在另一个答案中提到

So every time SublimeLinter executes in each *.py file being opened from the project, flake8 will be executed from that custom Python virtualenv binary.因此,每次在从项目打开的每个*.py文件中执行flake8都会从该自定义 Python virtualenv 二进制文件中执行flake8

Check out SublimePythonIDE (available on Package Control).查看SublimePythonIDE (可在包控制上找到)。 I believe it uses Pyflakes to lint your code by default.我相信它默认使用 Pyflakes 来检查您的代码。

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.我不认为它会主动将您的代码与虚拟环境进行 lint,但是您将可以访问诸如自动完成、跳转到定义、查看文档等内容。

In your project settings:在您的项目设置中:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM