【发布时间】:2017-02-22 07:58:02
【问题描述】:
我在 Mac OS X El Capitan 上使用 Sublim Text 3。我需要做的是在 Sublime Text 3 中评估一个 Python 文件。
我已经安装了Package Control 和SublimREPL 插件。
为了在屏幕的第二部分显示 Python 解释器,我设置了 2 行布局 (View > Layout > Rows: 2)。
然后我使用 Tools > Command Palette... > SublimeREPL: Python 启动 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 仍然启动)。
这是我Main.sublime-menu的内容:
[
{
"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",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["python", "-i", "-u", "-m", "pdb", "$file_basename"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python",
"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": ["python", "-u", "$file_basename"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python",
"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": ["python", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"],
"linux": ["python", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"],
"windows": ["python", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"]
},
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python",
"extend_env": {
"PYTHONIOENCODING": "utf-8",
"SUBLIMEREPL_EDITOR": "$editor"
}
}
}
]}
]
}]
}
]
仍然遵循this post的建议,我修改了下面的部分代码,但在文件夹/usr/local/bin/中找不到任何exe文件:
{"command": "repl_open",
"caption": "Python - PDB current file",
"id": "repl_python_pdb",
"mnemonic": "D",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["/usr/local/bin/python3", "-i", "-u", "-m", "pdb", "$file_basename"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python",
"extend_env": {"PYTHONIOENCODING": "utf-8"}
}
}
当我按Ctrl + , + f(根据doc)时,解释器仍以 Python 2.7.10 开始。
【问题讨论】:
-
对 OSX 不是很熟悉,但对于 linux,Python3.x 安装的可执行文件将命名为
python3或python35之类的名称。如果/usr/local/bin/像您提到的那样为空,那么它是否有可能安装到/usr/bin中,如果不是,/Library/Frameworks/甚至只是在应用程序中呢? -
另一件要尝试的事情,在命令行上,如果你可以让 python3 运行,
whereis python或which python会告诉你它的位置。同样,在 Python 3 解释器import site; print(site.USER_SITE)“应该”打印出 python3 的 site-packages 目录的位置。
标签: python macos sublimetext3 osx-elcapitan sublimerepl