Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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?

share|improve this question
    
Do you mean building Python 3 - that normally means getting the sources and building the python executable? I think you mean using Python 3 ie running a .py script through a python3 executable –  Mark Nov 1 '12 at 22:02
    
Yes I mean running the build command for a python script in SublimeText2 not building Python - will edit to clarify. –  markfknight Nov 1 '12 at 23:31
    
Thank you for editing in the code blocks, first question I have asked, will have to remember them next time. –  markfknight Nov 2 '12 at 13:00
add comment

3 Answers

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

share|improve this answer
1  
I'm doing the same with the line "cmd": ["usr/local/bin/python3", "-u", "$file"], really looking for a solution to have OSX do the leg work for me. –  markfknight Mar 20 '13 at 13:06
add comment

The issue is the normal OSX one that GUI Applications do not read your shell profiles etc and so just have the path inherited from the Workspace.

The way to fix this is to add the path in ~/.MacOSX/environment.plist

That is add a key string pair for PATH e.g.

<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>

  <key>PATH</key>
  <string>/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/libexec/binutils:</string>
</dict>
</plist>

You will need to logout and login or possibly reboot for this to work.

share|improve this answer
    
Created the folder and file before adding the key string pair, unfortunately I am still getting the error. do I need to add the path of Pyhton3 to the binary as well? –  markfknight Nov 3 '12 at 11:28
    
What does the path output in SublimeText show now? –  Mark Nov 3 '12 at 12:25
    
the path output is still showing [path: /usr/bin:/bin:/usr/sbin:/sbin] –  markfknight Nov 3 '12 at 17:26
    
I have added <Key>PATH<Key> and the following <String>/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:<String> to ~/.MacOSX/environment.plist, shutdown and started up, still getting this message. If I link directly to /usr/local/bin/python3 in the Python3.sublime-build file its builds with no issues. Can you help further? –  markfknight Nov 5 '12 at 18:57
    
Adding to the Sublime build probably is best –  Mark Nov 5 '12 at 19:36
add comment

Sister site stackoverflow has few entries with explanations regarding the issue of setting PATH environment variables for GUI based applications. Some claim that environment.plist works and others claim it doesn't and recommend using launched.conf.

Mac OS X Lion no longer recognizes environment.plist, Environment variables in Mac OS X, and Set environment variables on Mac OS X Lion. Also this answer has more details about launched.conf format.

share|improve this answer
    
Have tried both of these during my searches with no luck. –  markfknight Feb 2 '13 at 13:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.