## Select which version of Python to run/build?

### Select which version of Python to run/build?

Hello,

I'm curious if there's a way to select which version of Python I can choose to run.

As of now it's only running the 3x branch (I do have both versions installed, 2.7.1 and 3.2).

Is there a way for me to be able to select which version runs?

Thanks!
TVo

Posts: 5
Joined: Thu May 12, 2011 10:20 pm

### Re: Select which version of Python to run/build?

Hi TVo,

The default "Python.sublime-build" file should look something like this (Packages\User\Packages\Python\Python.sublime-build):

Code: Select all
{   "cmd": ["python", "-u", "$file"], "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)", "selector": "source.python"} To use a different version of python, change the "cmd" part of this build system (or better yet create a new build system) so it looks like this: Code: Select all { "cmd": ["C:\path\to\desired\version\python.exe", "-u", "$file"],   "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",   "selector": "source.python"}

Hope it helps.

Cheers,
Josh
jbjornson

Posts: 358
Joined: Tue Oct 27, 2009 4:25 pm
Location: Zurich, Switzerland

### Re: Select which version of Python to run/build?

Thank you very much, Josh!

That's exactly what I was looking for. I didn't see where the defaults were stored so I had nothing to look at to guide me.

I don't know Mac OSX or Linux file systems well enough, or how to properly type them out.

Could you perhaps show me an example of how to do this with a mac and linux as well?

I have been messing around with the settings but so far I haven't been able to get it to work.
TVo

Posts: 5
Joined: Thu May 12, 2011 10:20 pm

### Re: Select which version of Python to run/build?

Just so you know, I'm getting an error on my machine when I try using the full path.

The error says:

"Error trying to parse build system: Invalid escape in C:\Users\Me\AppData\Roaming\Sublime Text 2\Packages\User\Python27.sublime-build:2:10"

This is what I have written as my command:

Code: Select all
{   "cmd": ["C:\Python27\python.exe", "-u", "$file"], "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)", "selector": "source.python"} Any ideas? Do I need to add a "$(FULL_CURRENT_PATH)" in there anywhere?

Thanks for the help
TVo

Posts: 5
Joined: Thu May 12, 2011 10:20 pm

### Re: Select which version of Python to run/build?

I think the error is coming because the path you entered isn't correctly escaped. Try using:
Code: Select all
    {       "cmd": ["C:\\Python27\\python.exe", "-u", "$file"], "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)", "selector": "source.python" } Sorry, I didn't even think about it when I posted. Hopefully that helps... jbjornson Posts: 358 Joined: Tue Oct 27, 2009 4:25 pm Location: Zurich, Switzerland ### Re: Select which version of Python to run/build? TVo wrote:Thank you very much, Josh! Could you perhaps show me an example of how to do this with a mac and linux as well? It should be basically the same for linux or a mac - edit or create a new build system. You will need to include the appropriate path to the python executable. In linux you should be able to get the path by typing "which python" or "locate python" in a terminal window. Not sure on a mac, but those linux commands should also work. The nice thing in linux/mac is that you don't have to worry about escaping the paths, since "/" is used (as opposed to "\"). jbjornson Posts: 358 Joined: Tue Oct 27, 2009 4:25 pm Location: Zurich, Switzerland ### Re: Select which version of Python to run/build? That did it for the Windows version! Thanks for that. Seeing if I can figure out the Mac/Linux version. I'm just not familiar enough with the file system. Will the executable have a file extension on the Mac/Linux versions, or will I just write: "cmd": ["/Whatever/whatever/python", ... ? TVo Posts: 5 Joined: Thu May 12, 2011 10:20 pm ### Re: Select which version of Python to run/build? Normally linux/unix binaries (programs) do not have an extension (unlike windows that uses .exe). The default location for python should be in '/usr/bin/python', so in that case you would have: Code: Select all { "cmd": ["/usr/bin/python", "-u", "$file"],   "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",   "selector": "source.python"}

I'm not sure where other versions of python would be installed in linix so you will have to search for that using 'locate python' or something like that and update the build system accordingly.
jbjornson

Posts: 358
Joined: Tue Oct 27, 2009 4:25 pm
Location: Zurich, Switzerland

### Re: Select which version of Python to run/build?

That did it! Thanks again!
TVo

Posts: 5
Joined: Thu May 12, 2011 10:20 pm