4

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?

3
  • 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
    – mmmmmm
    Commented Nov 1, 2012 at 22:02
  • Yes I mean running the build command for a python script in SublimeText2 not building Python - will edit to clarify. Commented Nov 1, 2012 at 23:31
  • Thank you for editing in the code blocks, first question I have asked, will have to remember them next time. Commented Nov 2, 2012 at 13:00

4 Answers 4

4

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

2
  • 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. Commented Mar 20, 2013 at 13:06
  • @markfknight try using $(which python) in the build file.
    – anki
    Commented Sep 7, 2020 at 17:26
2

I gave the complete path to python3 to get this to work:

{
  "cmd" : ["/usr/local/bin/python3", "-u", "$file"],
}
1
  • This was the trick for mine.
    – JacobIRR
    Commented Sep 8, 2017 at 17:04
1

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.

5
  • 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? Commented Nov 3, 2012 at 11:28
  • What does the path output in SublimeText show now?
    – mmmmmm
    Commented Nov 3, 2012 at 12:25
  • the path output is still showing [path: /usr/bin:/bin:/usr/sbin:/sbin] Commented Nov 3, 2012 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? Commented Nov 5, 2012 at 18:57
  • Adding to the Sublime build probably is best
    – mmmmmm
    Commented Nov 5, 2012 at 19:36
0

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.

1
  • Have tried both of these during my searches with no luck. Commented Feb 2, 2013 at 13:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .