Sublime Forum

Mac M1 path issues?

#1

First things first, my terminal path is /opt/homebrew/bin /opt/homebrew/sbin /usr/local/bin /usr/bin /bin /usr/sbin /sbin. I’m on a M1 Mac running Monterey. I installed Python using Homebrew.

A few months ago, something weird changes with my system, maybe due to Xcode being installed. Basically, if I have build system set to ‘automatic’ and try to build a Python file, I get bash: python: command not found. Path in SublimeText shows as [path: /opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin].

If I set build system to ‘Python’, for some reason it’s running the wrong Python. If I print sys.path, I get: ['/Users/myname/myfolder/', '/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python38.zip', '/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8', '/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/lib-dynload', '/Users/myname/Library/Python/3.8/lib/python/site-packages', '/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/site-packages']

I know I can make a custom build system to point to where my Python should be run from (/opt/homebrew/bin/), but I created a whole other issue when I tried to do that. Shouldn’t I be able to leave the build system on Automatic??

0 Likes

#2

What build of Sublime are you running? You mention an M1 so my guess would be ST4 for performance reasons, but perhaps you are using an older version using rosetta instead?

In ST4, the Python.sublime-build file that ships tries to run python3 on Linux and MacOS and py on Windows; prior versions of Sublime try to run just python, which generally finds the wrong version because python is Python 2 and python3 is used for Python 3 (different executable since they’re not 100% code compatible in all cases)

In the absence of an existing custom build (which includes not only a sublime-build file but also builds inside of sublime-project files, the only build that would be used to execute Python would execute one of the two (depending on the version) and should do the same thing either way.

So, the first thing to check would be, is there already some extra custom build. While you have a Python file open, make sure the build is set to Automatic and then do Tools > Build With... ; what options are you offered?

It’s also worth pointing out that whatever you think your PATH is set to on MacOS (say by checking it in a terminal), that’s not the PATH that applications executed outside of the terminal see because the OS uses a different configuration for applications started via the launcher.

Sublime has a setting for MacOS (enabled by default) that will execute a shell and capture the environment, and set itself up with that. Since that’s turned on by default, if everything is set up correctly for your shell, Sublime should always see the same path as the Terminal does.

You can verify if that’s the case or not by checking the Sublime console for a message; it should say that it’s doing it (if I recall correctly, it’s been a while) and it will also tell you if it failed to do it.

Presuming that’s working, you need to make sure that the appropriate setup is being done by your shell; how you do that depends on what shell you use, but if you check out the docs on the command line interface it mentions which files need to be updated; either .bash_profile or .zprofile, depending on your shell.

0 Likes