简体   繁体   English

Python 构建不适用于 Sublime Text

[英]Python build doesn't work on Sublime Text

Whenever I build ( Cmd+B ) on Sublime Text 3 it doesn't execute my code.每当我在 Sublime Text 3 上构建( Cmd+B )时,它都不会执行我的代码。

I used Shift+Command+B to set the build system to Python.我使用Shift+Command+B将构建系统设置为 Python。 I also tried making my own build system by using the which python3.6 command in terminal, which said /Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6我还尝试通过在终端中使用which python3.6命令来制作自己的构建系统,该命令说/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6

I put in this in my custom build system我把它放在我的自定义构建系统中

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

However I still get the same error.但是我仍然遇到同样的错误。 Please help.请帮忙。

这就是我尝试构建时得到的

I know this is a really stupid question, I'm sure I just have to change some settings to solve this, thanks for you time.我知道这是一个非常愚蠢的问题,我确定我只需要更改一些设置来解决这个问题,感谢您的时间。

Looks like Python can't find anything to build.看起来 Python 找不到任何要构建的东西。

A couple of quick things:一些快速的事情:

  1. You don't seem to have saved your file.您似乎没有保存文件。 Save it with a .py extention.使用 .py 扩展名保存它。
  2. Is Python on your path? Python 在你的道路上吗? Try to type " python " in a cmd terminal.尝试在 cmd 终端中输入“python”。

For sublime text, it's better to use package: Anaconda.对于崇高的文本,最好使用包:Anaconda。

Here is a blog is written in Chinese, but you can follow the pics: https://hanbaobao2005.wordpress.com/2016/06/07/python%E5%A4%9A%E7%89%88%E6%9C%AC-sublime-text-anaconda%E6%8C%87%E5%8C%97/这里有一篇中文博客,但你可以关注图片: https : //hanbaobao2005.wordpress.com/2016/06/07/python%E5%A4%9A%E7%89%88%E6%9C% AC-sublime-text-anaconda%E6%8C%87%E5%8C%97/

Open a new file and write this:打开一个新文件并写入:

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

Save the file as Python3.sublime-build , then change your Build System to Python3 and try to run your code again.将文件另存为Python3.sublime-build ,然后将您的构建系统更改为 Python3 并尝试再次运行您的代码。 Now, it should run successfully.现在,它应该可以成功运行。

In my case, I found that the problem was with this line, "selector": "source.python".就我而言,我发现问题出在这一行,“selector”:“source.python”。 Once I changed it to "selector": "source.py", and re-open the python program file, it worked.一旦我将其更改为“选择器”:“source.py”,然后重新打开 python 程序文件,它就可以工作了。

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

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