Sublime Forum

PATH Environment Variable incomplete (OSX)

#1
I'm trying to configure the LSP from packagecontrol and keep running into issues because the Go and JSON plugins cannot find their runtime tools.

I’ve tried many things but most importantly, I now know that running os.environ['PATH'] and os.getenv("PATH") both return /usr/bin:/bin:/usr/sbin:/sbin whereas cat /etc/paths echoes:

/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

I’ve tried making links from the relevant binaries to the places I expect sublime can check but I can’t gain permissions, not even when using sudo.

I also know that the os I’m using in the console is python bytecode. Without having to hack that myself…

what’s a good way to make sure that the path sublime has access to is the same as the one found at /etc/paths?


For anyone with a similar issue who just wants to get up and running At the moment I've just added `os.environ["PATH"] += os.pathsep + "/usr/local/bin"` near the top of every file that uses `os.getenv` or `os.environ`. This works because they reference the same underlying dictionary, but it would be good to configure this globally in order to avoid having to do this again for every package that doesn't offer manual entry of dependency paths.

this may come in handy:

import os
import re


def lines(path: str) -> iter:
    with open(path, 'r') as fobj:
        yield from fobj.readlines()


def files(root: str, ext: str = ".py") -> iter:
    # use ext="" to match all path endings
    for name in os.listdir(root):
        path = os.path.join(root, name)
        if os.path.isdir(path):
            yield from files(path, ext)
        elif name.endswith(ext):
            yield path


if __name__ == "__main__":
    pattern = re.compile("environ|getenv")
    for file in files("path"):
        if any(map(pattern.match, lines(file))):
            print(file)
0 Likes