如何在Sublime Text 3中运行python 3.5

时间:2016-02-27 08:00:28

标签: python python-3.x sublimetext3

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

任何人都可以指导我使用包运行它的过程,如next

2 个答案:

答案 0 :(得分:9)

是的,您可以使用任何想要从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中的说明进行操作。

答案 1 :(得分:1)

如果你已经安装了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 /

希望这有帮助!