Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run Python 3 in Sublime 2 REPL Mac

My question is the following, I have sublime 2 and sublime repl plugin installed all working fine, the only thing i need is to change the version of python that is running on the sublimerepl built in console. What I mean is, I have python 2.7.5 (which is pre installed with maveriks) running fine in sublime (via sublimerepl), and I have installed via the installer from python.org, python 3.3.3 , that I need to use, I want to run this version of python on the sublimerepl console but I don't know how.

I know that there are alternatives to sublime but none of those are so beautiful as sublime is.

Can someone help me with this ? I've searched for all over the internet and couldn't find anything helpful.

Btw if I use terminal python 3.3.3 is working fine (Terminal>'python3'), I know this is possible beacause a friend of mine got it working and I have installed mine like he did, but mine is not working.

like image 489
jbernardo Avatar asked Dec 25 '13 22:12

jbernardo


People also ask

How do I run Python 3 Sublime on Mac?

Now go to Tools -> Build System, and select Python3 (or whatever you named your Build System). If you don't see your new build system, you may have to quit Sublime Text and reopen it. Now run the same code to test which version of Python you're using. There you go, Python 3.7 up and running.

How do I run a script in Sublime Text Mac?

To run code in Sublime Text, go to Tools > Build System, and select the language for your code (Sublime comes with support for various languages like Python, Ruby, Bash, and more). Next, press Cmd+B on Mac or Ctrl+B on Windows to run your code.


2 Answers

@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 image 167
MattDMo Avatar answered Sep 22 '22 01:09

MattDMo


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.

like image 20
poke Avatar answered Sep 26 '22 01:09

poke