How do I run python 3.5 in Sublime Text 3

梦想与她 提交于 2019-12-03 08:52:11
MattDMo

Yes, you can use any Python version you want to run programs from Sublime - you just need to define a new build system. Select Tools -> Build System -> New Build System, then delete its contents and replace it with:

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

assuming that C:/Python35/python.exe is the correct path. If python.exe resides someplace else, just put in the correct path, using forward slashes / instead of the Windows standard backward slashes \.

Save the file as Packages/User/Python3.sublime-build, where Packages is the folder opened by selecting Preferences -> Browse Packages... - Sublime should already automatically save it in the right directory. Now, there will be a Tools -> Build System -> Python3 option that you can select for running files with Python 3.

For details on setting up SublimeREPL with Python 3, please follow the instructions in my answer here.

if you have installed python3 and SublimeREPL, you can try setting up key bindings with the correct path to the python3 file.

[
     {
        "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"}
                        }
    }
]

You can try by copying this code into your /Sublime Text 3/Preferences/Key Bindings/

Hope this helps!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!