【问题标题】:How do I run python 3.5 in Sublime Text 3如何在 Sublime Text 3 中运行 python 3.5
【发布时间】:2016-02-27 08:00:28
【问题描述】:

我已在我的设备 (Windows) 中安装了 python 3.5 解释器。

谁能像SublimeREPL一样指导我使用软件包来运行它?

【问题讨论】:

  • 我想你可能想在 sublime text 上为 python3.5 创建一个新的build system。您也许可以复制现有的 python 构建系统并对其进行修改以供您使用。

标签: python python-3.x sublimetext3


【解决方案1】:

是的,你可以使用任何你想从 Sublime 运行程序的 Python 版本——你只需要定义一个新的build system。选择Tools -> Build System -> New Build System,然后删除其内容并替换为:

{
    "cmd": ["C:/Python35/python.exe", "-u", "$file"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python"
}

假设C:/Python35/python.exe 是正确的路径。如果python.exe 位于其他位置,只需输入正确的路径,使用正斜杠/ 而不是Windows 标准的反斜杠\

将文件另存为Packages/User/Python3.sublime-build,其中Packages 是通过选择Preferences -> Browse Packages... 打开的文件夹 - Sublime 应该已经自动将其保存在正确的目录中。现在,您可以选择一个 Tools -> Build System -> Python3 选项来使用 Python 3 运行文件。

有关使用 Python 3 设置 SublimeREPL 的详细信息,请按照my answer here 中的说明进行操作。

【讨论】:

  • 对于 unix,在终端中使用 which python3 获取您的 python 路径以替换“C:/Python35/python.exe”。
【解决方案2】:

如果你已经安装了 python3 和 SublimeREPL,你可以尝试使用 python3 文件的正确路径设置键绑定。

[
     {
        "keys":["super+ctrl+r"],
        "command": "repl_open",
                     "caption": "Python 3.6 - Open File",
                     "id": "repl_python",
                     "mnemonic": "p",
                     "args": {
                        "type": "subprocess",
                        "encoding": "utf8",
                        "cmd": ["The directory to your python3.6 file", "-i", "$file"],
                        "cwd": "$file_path",
                        "syntax": "Packages/Python/Python.tmLanguage",
                        "external_id": "python",
                        "extend_env": {"PYTHONIOENCODING": "utf-8"}
                        }
    }
]

您可以尝试将此代码复制到 /Sublime Text 3/Preferences/Key Bindings/ 中

希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-01
    • 1970-01-01
    • 2017-05-22
    • 2015-05-17
    • 1970-01-01
    • 1970-01-01
    • 2014-08-05
    • 1970-01-01
    相关资源
    最近更新 更多