2

I've created a python3.sublime-build:

{
  "path": "/usr/local/bin/python",
  "cmd": ["python3", "-u", "$file"],
  "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
  "selector": "source.python"
}

and $ which python3 returns,

/usr/local/bin/python3

likely installed with brew.

and Command + B returns this error:

[Errno 20] Not a directory
[cmd: ['python3', '-u', '/path/to/dir/filename.py']]
[dir: /path/to/dir]
[path: /usr/local/bin/python]
[Finished]

have looked into some relevant posts, and couldn't solve it.

How do I solve the problem?

wim
  • 338,267
  • 99
  • 616
  • 750
Emma
  • 27,428
  • 11
  • 44
  • 69
  • 3
    Try deleting the "path" key from your build system. I don't see that documented here https://www.sublimetext.com/docs/3/build_systems.html And I have [a successful python3 build system](https://stackoverflow.com/a/42819169/674039) without it. – wim Jul 31 '19 at 18:29
  • 2
    `path` is valid (so long as you use `shell_cmd` and not `cmd`) but it sets the PATH to exactly what you set the string to, and here that's not valid. It's generally a better idea to use `env` instead of `path` (though `env` is a dictionary and not a string) to modify the environment though. If you use `path` and the build breaks in certain ways, the environment will be clobbered and broken (breaking **all** builds) until you restart Sublime. – OdatNurd Jul 31 '19 at 18:31
  • 1
    The problem is "path", and I think you have a fix. It's worth mentioning - you might want to consider switching from Sublime to Visual Studio Code. Just a thought... – paulsm4 Jul 31 '19 at 18:32
  • 1
    Just noticed that I said that backwards above; `path` works for `cmd` and not for `shell_cmd`, not the other way around. `cmd` directly launches the first item in `cmd` but `shell_cmd` is passed to the system shell. So using `path` with `shell_cmd` only affects the system's ability to find the shell and not the shell's ability to find what you asked it run. Sorry about that. – OdatNurd Jul 31 '19 at 18:52

2 Answers2

5

IIRC (I haven't used Sublime in a while), path should be the path to the directory, not the executable. Try this instead:

{
  "path": "/usr/local/bin/",
  "cmd": ["python3", "-u", "$file"],
  "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
  "selector": "source.python"
}

It seems like Python is already in your system PATH though, so the path key seems unnecessary.

iz_
  • 15,923
  • 3
  • 25
  • 40
  • 1
    Or alternatively, just delete the "path" entry ;) – paulsm4 Jul 31 '19 at 18:33
  • 3
    If `which python3` returns the location of the interpreter, there's no reason to try and modify the path at all because it's already set up. Just removing `path` will solve the problem (though you may have to restart Sublime afterwards because using `path` indiscriminately can clobber the environment) – OdatNurd Jul 31 '19 at 18:34
  • @OdatNurd Thanks, I was just editing when you made your comment :) – iz_ Jul 31 '19 at 18:35
  • 2
    @iz_ yeah, GMTA :) – OdatNurd Jul 31 '19 at 18:35
0

Delete the "path" key from your build system. It is not required.

{
  "cmd": ["python3", "-u", "$file"],
  "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
  "selector": "source.python"
}

That was causing the [Errno 20] Not a directory problem, since the configured path was resolving to a file instead of to a directory.

Location to save the build file on macOS:

~/Library/Application Support/Sublime Text 3/Packages/User/python3.sublime-build
wim
  • 338,267
  • 99
  • 616
  • 750
  • 1
    @Emma You may have needed to restart Sublime to get it to work again. When you use `path` it replaces the system PATH for Sublime to be what you said, and then it sets it back when the build finishes. If the build finishes with an error like the one above it skips over the reset part, which leaves the PATH broken for Sublime until you restart it. – OdatNurd Jul 31 '19 at 18:53