MacOS – How to setup Python3.3 and Sublime Text 2 correctly on OS X 10.8.2

macospythonsublimetexttext-editor

I am trying to setup Sublime Text 2 so that the build command correctly runs Python3 / Python3.3 scripts.

I have installed Python 3.3 via the installer obtained from python.org and installed Sublime Text 2 via the Sublime Text 2 installer.

Following this I added a custom build entry called:

Python3.sublime-build 

into Sublime Text 2's Python folder with the following contents:

{
    "cmd": ["python3", "-u", "$file"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python"
}

I'm getting the following error when trying to run the script:

[Errno 2] No such file or directory
[cmd:  [u'python3', u'-u', u'/Users/user/Library/Application Support/Sublime Text 2/Packages/Python/Python3.sublime-build']]
[dir:  /Users/user/Library/Application Support/Sublime Text 2/Packages/Python]
[path: /usr/bin:/bin:/usr/sbin:/sbin]
[Finished]

I have read somewhere that symlinkng python3 from /usr/bin might fix the issue but after creating the symlink in /usr/bin through Finder, Sublime Text still cannot build as it gets a permissions error.

What is the best way to set Sublime Text 2 up to allow for running Python3 scripts?

[edit]

If I place the PATH for the python3 simlink generated by install, Sublime Text 2 can build the script,

    {
        "cmd": ["usr/local/bin/python3", "-u", "$file"],
        "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
        "selector": "source.python"
    }

But when I tried adding the PATH to the ~/.MacOSX/environment.plist as advised without the defined PATH I get the error. Could anyone point out why this is not working?

Best Answer

Add "path": "/Library/Frameworks/Python.framework/Versions/3.3/bin/" to your Python3 build file. Mine looks like this:

{
    "cmd": ["python3", "-u", "$file"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python",
    "encoding": "utf8",
    "path": "/Library/Frameworks/Python.framework/Versions/3.3/bin/"
}

Note: Make sure the path to Python3 is relative to your machine - that was true for mine