我在Mac OS X El Capitan上使用Sublim Text 3.我需要做的是评估Sublime Text 3中的Python文件.
我已经安装了Package Control,然后安装了SublimREPL插件.
我已经设置了2行布局(View> Layout> Rows:2),以便在屏幕的第二部分显示Python解释器.
然后我用Tools>启动Python解释器.命令调色板…> SublimeREPL:Python.
解释器正确启动,我得到了这个:
我找不到如何从我手动下载的Python 3.5开始(因此安装在/usr/local/bin /中).我试图修改这个文件:/ Library / Application Support / Sublime Text 3 / Packages / SublimeREPL / Config / Python / Main.sublime-menu遵循this post指令,但这没有改变任何东西(Python 2.7.10仍然推出).
[
{
"id": "tools","children":
[{
"caption": "SublimeREPL","mnemonic": "R","id": "SublimeREPL","children":
[
{"caption": "Python","id": "Python","children":[
{"command": "repl_open","caption": "Python","id": "repl_python","mnemonic": "P","args": {
"type": "subprocess","encoding": "utf8","cmd": ["python","-i","-u"],"cwd": "$file_path","Syntax": "Packages/Python/Python.tmLanguage","external_id": "python","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","-u","-m","pdb","$file_basename"],"caption": "Python - RUN current file","id": "repl_python_run","caption": "Python - IPython","id": "repl_python_ipython","mnemonic": "I","autocomplete_server": true,"cmd": {
"osx": ["python","${packages}/SublimeREPL/config/Python/ipy_repl.py"],"linux": ["python","windows": ["python","${packages}/SublimeREPL/config/Python/ipy_repl.py"]
},"extend_env": {
"PYTHONIOENCODING": "utf-8","SUBLIMEREPL_EDITOR": "$editor"
}
}
}
]}
]
}]
}
]
仍然遵循this post建议,我修改了下面的代码部分,但我在文件夹/usr/local/bin /中找不到任何exe文件:
{"command": "repl_open","args": {
"type": "subprocess","cmd": ["/usr/local/bin/python3","extend_env": {"PYTHONIOENCODING": "utf-8"}
}
}
当我按下Ctrl,f(根据doc)时,解释器仍然以Python 2.7.10开头.
I then launch the Python interpreter with
Tools > Command Palette... > SublimeREPL: Python
没有命令调色板项“SublimeREPL:Python”,所以我假设你的意思是工具> SublimeREPL> Python>Python.这将打开一个类似于以下内容的选项卡:
# *REPL* [python]
Python 2.7.6 (default,Jun 22 2015,17:58:13)
[GCC 4.8.2] on linux2
Type "help","copyright","credits" or "license" for more information.
>>>
实际上工具> SublimeREPL> Python显示如下所示的菜单:
Python - execnet
Python
Python - virtualen
Python - PDB current file
Python - RUN current file
Python - IPython
到现在为止还挺好.但是如何更改Python版本?
理想情况下,我们可以将全局python配置为使用(似乎不可能),也可以将版本变量添加到上面描述的菜单中(这似乎也不可能).
创建名为Packages / User / Menu.sublime-menu的文件(如果它尚不存在).通过菜单>找到用户包目录偏好>浏览包…).并在该文件中创建菜单.此菜单将添加到现有菜单中.
例如:
[
{
"id": "tools","children":
[{
"caption": "SublimeREPL Variants","id": "SublimeREPLVariants","children":
[
{
"command": "repl_open","cmd": ["/usr/bin/python3","extend_env": {"PYTHONIOENCODING": "utf-8"}
}
}
]
}]
}
]
重要的是:
>标题和id与任何其他菜单不同,否则它将替换其他菜单,因此我将上面的名称命名为“SublimeREPL Variants”.
>“cmd”使用有效二进制文件的绝对路径.您可以使用以下命令检查您是否使用了正确的路径:
找到Python的位置,通过该位置:
$which python
/usr/bin/python
$which python3
/usr/bin/python3
$which python2
/usr/bin/python2
有关其他详细信息,请参见Possible to switch between python 2 and 3 in Sublime Text 3 build systems? (Windows).