栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

崇高的text3和virtualenvs

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

崇高的text3和virtualenvs

希望这是您所想象的路线。我试图简化解决方案,并删除一些您可能不需要的东西。

这种方法的优点是:

  • 只需按一下按钮即可启动具有正确解释器的SublimeREPL, 在需要时在其中运行文件。
  • 设置解释器后,在项目之间切换时无需进行任何更改或其他步骤。
  • 可以轻松扩展以自动选择项目特定的环境变量,所需的工作目录,运行测试,打开Django shell等。

让我知道您是否有任何疑问,或者我是否完全想念您要做什么。

设置项目的Python解释器

  1. 打开我们的项目文件进行编辑:

    Project -> Edit Project
  2. 在项目设置中添加一个新密钥,该密钥指向所需的virtualenv:

        "settings": {        "python_interpreter": "/home/user/.virtualenvs/example/bin/python"    }

一个

"python_interpreter"
项目设置键也被类似的插件蟒蛇。

创建插件以获取此设置并启动SublimeREPL

  1. 浏览到Sublime Text的

    Packages
    目录:

    Preferences -> Browse Packages...
  2. 为我们的插件创建一个新的python文件,如下所示:

    project_venv_repls.py

  3. 将以下python代码复制到此新文件中:

        import sublime_plugin    class ProjectVenvReplCommand(sublime_plugin.TextCommand):        """        Starts a SublimeREPL, attempting to use project's specified        python interpreter.        """        def run(self, edit, open_file='$file'): """Called on project_venv_repl command""" cmd_list = [self.get_project_interpreter(), '-i', '-u'] if open_file:     cmd_list.append(open_file) self.repl_open(cmd_list=cmd_list)        def get_project_interpreter(self): """Return the project's specified python interpreter, if any""" settings = self.view.settings() return settings.get('python_interpreter', '/usr/bin/python')        def repl_open(self, cmd_list): """Open a SublimeREPL using provided commands""" self.view.window().run_command(     'repl_open', {         'encoding': 'utf8',         'type': 'subprocess',         'cmd': cmd_list,         'cwd': '$file_path',         'syntax': 'Packages/Python/Python.tmLanguage'     } )

设置热键

  1. 打开用户密钥绑定文件:

    Preferences -> Key Bindings - User
  2. 添加一些按键绑定以使用插件。一些例子:

        // Runs currently open file in repl    {        "keys": ["f5"],        "command": "project_venv_repl"    },    // Runs repl without any file    {        "keys": ["f6"],        "command": "project_venv_repl",        "args": { "open_file": null        }    },    // Runs a specific file in repl, change main.py to desired file    {        "keys": ["f7"],        "command": "project_venv_repl",        "args": { "open_file": "/home/user/example/main.py"        }    }


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/610475.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号