3

I want to build a python file I get the following error:

/bin/bash: python: command not found

The reason is that I'm using zsh instead of bash. So how to let Sublime to look at /bin/zsh?

ChenYang
  • 441
  • 7
  • 13
  • 2
    What has Sublime Text got to do with anything? Are you talking about running a build from within Sublime Text? – Droppy Jul 25 '16 at 13:29
  • Yes. I mean to run a build whith Sublime Text.(Tools > Build) – ChenYang Jul 25 '16 at 13:36
  • You've done something to mess up your global `$PATH` as python is in `/usr/bin`, which is set-up correctly by default. – Droppy Jul 25 '16 at 14:02
  • The output of echo "$PATH" in Terminal is `/usr/local/sbin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/Users/chenyang/Downloads/android-sdk-macosx/platform-tools`. I met the same problem when I used CodeRunner and I solved it in CodeRunner(http://stackoverflow.com/q/38554566/6631854). – ChenYang Jul 25 '16 at 14:23
  • That's from the shell, but UI programs get a different `$PATH`. I think you were told this in the last question you asked on the subject. – Droppy Jul 25 '16 at 14:24
  • I know on OS X, Sublime Text has its PATH set by launchctl, not by the shell. I also tried `launchctl setenv PATH "$PATH"` but it failed. – ChenYang Jul 25 '16 at 14:30
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/118235/discussion-between-chenyang-and-droppy). – ChenYang Jul 25 '16 at 14:30

3 Answers3

6

This is indicative of your path not being correct and not what shell you normally use. In the case of OSX the path for GUI applications is set via different means than that of terminal programs (which you know based on your comments in your question above).

Regardless, to answer your question (and for future reference) the exec command in Sublime, which is used to execute tasks including build systems, is what is specifying that things be executed via bash.

Using PackageResourceViewer you can extract the file exec.py from the Default package and modify it's use of "/bin/bash" to "/bin/zsh" (or whatever other shell you want) as you see fit.

[EDIT]

While the above will work, when you override a file from a package like this, your override persists forever. That is to say, if a newer version of Sublime includes a different version of exec.py with bug fixes or newer features, you won't see them because you've overridden the file.

So something to keep in mind is that if you take this route the onus is on you to always keep your override up to date with the current released version. Bug reports of exec problems are probably also going to fall on deaf ears or cause tears when it's discovered you've overridden the file.

OdatNurd
  • 21,371
  • 3
  • 50
  • 68
2

If all that you need is to open zsh shell from sublime rather than the default bash shell, there is a simpler way to do this. On OSX/Mac, open perferences->package settings->terminal view->pallete commands. Change /bin/bash to /bin/zsh like below.

{ "args" : {"title": "Terminal (bash)", "cmd": "/bin/zsh -l"}, },

This works for sublime text 3. Have not tested for lower versions.

Hope this helps!! Cheers!!

nikhil
  • 9,023
  • 22
  • 55
  • 81
0

It work for me fine on Mojave.

sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/bin
Kiryl Plyashkevich
  • 2,157
  • 19
  • 18