简体   繁体   中英

How to run Python3 on Sublime Text 3 on macOS?

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?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM