Not realizing that the build command (⌘b) in ST4 uses bash by default on macOS caused me a big headache recently. It took me days to figure out that the reason I wasn’t able to get my one Python script to run (I kept getting ModuleNotFoundError) was because sublime by default uses the bash shell and NOT zsh. zsh is the default on macOS and has been for years now. Since ST4 wasn’t seeing the same python3 executable on the PATH (or the same PATH for that matter) my script wasn’t running properly. If I ran it in terminal it worked fine without any errors.
After reading more about the build systems I came across this one line in regards to the shell_cmd string: “A shell command [executes using] bash on Mac and Linux” sublime docs - build system.
I found a few different ways to fix this:
- Modifying
.bash_profileto match the exports, assignments, andPATHsetup that I have in.zprofileand.zshrc. - Changing the default build system configuration for python (
Python.sublime-build):
"shell_cmd": "python3 -u \"$file\""
// to this
"shell_cmd": "/full_path_to_python/python -u \"$file\""
- Overriding the default
exec.pyfile (making a new file inPackages/Default/exec.py) and changing:
elif sys.platform == "darwin":
# Use a login shell on OSX, otherwise the users expected env
# vars won't be setup
cmd = ["/usr/bin/env", "bash", "-l", "-c", shell_cmd]
# to
cmd = ["/usr/bin/env", "zsh", "-l", "-c", shell_cmd]
While changing my .bash_profile is probably the easiest thing, sublime should be using zsh to align with the default on macOS. It would also be nice if this was a user configurable setting that wasn’t hidden in some obscure exec.py file in the compressed Default directory.