可使用Package Control安装SublimeREPL插件,
具体安装方法请参考https://blog.csdn.net/lylfv/article/details/81452582
使用SublimeREPL插件执行python文件
Tools-> SublimeREPL->Python->Python-RUN current file
测试代码(Python3.6.1测试通过)
def multi(x):
return x ** 3
if __name__ == '__main__':
var = int(input('Please input a number: '))
print(multi(var))
Sublime Text 3-> Preferences-> Key Bindings
输入下列内容并保存:
[
{
"keys":["f5"],
"caption": "SublimeREPL: Python - RUN current file",
"command": "run_existing_window_command", "args": {"id": "repl_python_run",
"file": "config/Python/Main.sublime-menu"}
}
]
Preferences-> Browse Packages
打开SublimeREPL->config文件夹
新建Python3文件夹,并添加下列文件(可参考Python文件夹)
Default.sublime-commands
Main.sublime-menu
修改Default.sublime-commands,内容如下:
[
{
"caption": "SublimeREPL: Python3",
"command": "run_existing_window_command", "args":
{
"id": "repl_python3",
"file": "config/Python3/Main.sublime-menu"
}
},
{
"caption": "SublimeREPL: Python - PDB current file",
"command": "run_existing_window_command", "args":
{
"id": "repl_python_pdb",
"file": "config/Python3/Main.sublime-menu"
}
},
{
"caption": "SublimeREPL: Python3 - RUN current file",
"command": "run_existing_window_command", "args":
{
"id": "repl_python3_run",
"file": "config/Python3/Main.sublime-menu"
}
},
{
"command": "python_virtualenv_repl",
"caption": "SublimeREPL: Python - virtualenv"
},
{
"caption": "SublimeREPL: Python - IPython",
"command": "run_existing_window_command", "args":
{
"id": "repl_python_ipython",
"file": "config/Python3/Main.sublime-menu"
}
}
]
5.修改Main.sublime-menu,内容如下:
[
{
"id": "tools",
"children":
[{
"caption": "SublimeREPL",
"mnemonic": "R",
"id": "SublimeREPL",
"children":
[
{"caption": "Python3",
"id": "Python3",
"children":[
{"command": "repl_open",
"caption": "Python3",
"id": "repl_python3",
"mnemonic": "P",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["python3", "-i", "-u"],
"cwd": "$file_path",
"syntax": "Packages/Python3/Python.tmLanguage",
"external_id": "python3",
"extend_env": {"PYTHONIOENCODING": "utf-8"}
}
},
{"command": "python_virtualenv_repl",
"id": "python_virtualenv_repl",
"caption": "Python - virtualenv"},
{"command": "repl_open",
"caption": "Python - PDB current file",
"id": "repl_python_pdb",
"mnemonic": "D",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["python3", "-i", "-u", "-m", "pdb", "$file_basename"],
"cwd": "$file_path",
"syntax": "Packages/Python3/Python.tmLanguage",
"external_id": "python3",
"extend_env": {"PYTHONIOENCODING": "utf-8"}
}
},
{"command": "repl_open",
"caption": "Python - RUN current file",
"id": "repl_python_run",
"mnemonic": "R",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["python3", "-u", "$file_basename"],
"cwd": "$file_path",
"syntax": "Packages/Python3/Python.tmLanguage",
"external_id": "python3",
"extend_env": {"PYTHONIOENCODING": "utf-8"}
}
},
{"command": "repl_open",
"caption": "Python - IPython",
"id": "repl_python_ipython",
"mnemonic": "I",
"args": {
"type": "subprocess",
"encoding": "utf8",
"autocomplete_server": true,
"cmd": {
"osx": ["python3", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"],
"linux": ["python3", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"],
"windows": ["python3", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"]
},
"cwd": "$file_path",
"syntax": "Packages/Python3/Python.tmLanguage",
"external_id": "python3",
"extend_env": {
"PYTHONIOENCODING": "utf-8",
"SUBLIMEREPL_EDITOR": "$editor"
}
}
}
]}
]
}]
}
]