简体   繁体   English

如何在 macOS 上的 Sublime Text 3 上运行 Python3?

[英]How to run Python3 on Sublime Text 3 on macOS?

I've created a python3.sublime-build :我创建了一个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,$ which python3返回,

/usr/local/bin/python3

likely installed with brew .可能与brew安装。

and Command + B returns this error:并且Command + B返回此错误:

[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. IIRC(我有一段时间没有使用 Sublime), path应该是目录的路径,而不是可执行文件。 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.不过,似乎 Python 已经在您的系统 PATH 中,因此path键似乎是不必要的。

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.这导致[Errno 20] Not a directory问题,因为配置的路径解析为文件而不是目录。

Location to save the build file on macOS:在 macOS 上保存构建文件的位置:

~/Library/Application Support/Sublime Text 3/Packages/User/python3.sublime-build

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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