How to run Python 3 in Sublime 2 REPL Mac

落爺英雄遲暮 提交于 2019-12-05 09:21:59
MattDMo

@poke's answer is good, but there are a few details to correct that I figured I'd just put in my own answer as they're too long for comments. First, the .sublime-menu entry should be named Packages/User/SublimeREPL/config/Python/Main.sublime-menu (naming the file something else won't integrate it into the menu system, it has to be Main.sublime-menu AFAIK). Also, for your system, you should probably change the "cmd" lines to point to /Library/Frameworks/Python.framework/Versions/3.3/bin/python3, which is where the python.org installation is located. So, for example, where it says

"cmd": ["python", "-i", "-u"],

change that to

"cmd": ["/Library/Frameworks/Python.framework/Versions/3.3/bin/python3", "-i", "-u"],

Good luck!

Like it or not, but the interpreter is actually hardcoded into the plugin. For Python, this happens in /config/Python/Main.sublime-menu.

I think you have two ways to work around this:

  1. The first option would be to copy that Main.sublime-menu file into your local user configuration folder, if you already have one there, you will need to merge both contents. Replace all the python calls by python3, and adjust the caption properties to mention Python 3 (e.g. Python 3 - RUN current file).

    Now, when you launch the command launcher via Cmd+Shift+P (should be the keyboard shortcut in OSX, right?), then you can type Python 3 and your new commands using the python3 executable should pop up.

  2. The second option would be to clone the plugin into your plugin directory, and modify the original Python Main.sublime-menu file in the same way as in the first option. This will get rid of the Python 2 commands, but also prevent you from getting updates from the original repository published over PackageManager; so you would have to make updates yourself.

my workaround was this:

Open the file: /Users/ricardomartinez/Library/Application Support/Sublime Text 3/Packages/SublimeREPL/config/Python/Main.sublime-menu

replace the line that says:

"cmd": ["python", "-i", "-u", "-m", "pdb", "$file_basename"],

with:

"cmd": ["/Library/Frameworks/Python.framework/Versions/3.5/bin/python3", "-i", "-u"],

note that is necessary specify the whole route of the python3 exec because i read in another question that Sublime don't read the ~/.bash_profile

Hope that help!

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