How do I run Python code from Sublime Text 2?

I want to set up a complete Python IDE in Sublime Text 2.

I want to know how to run the Python code from within the editor. Is it done using build system? How do I do it ?


Tools -> Build System -> (choose) Python then:

To Run:

      Tools -> Build

      -or-

      Ctrl + B

      CMD + B  (OSX)

This would start your file in the console which should be at the bottom of the editor.

To Stop:

       Ctrl + Break or Tools -> Cancel Build

       Fn + C (OSX)

You can find out where your Break key is here: http://en.wikipedia.org/wiki/Break_key.

Note: CTRL + C will NOT work.

What to do when Ctrl + Break does not work:

Go to:

Preferences -> Key Bindings - User

and paste the line below:

{"keys": ["ctrl+shift+c"], "command": "exec", "args": {"kill": true} } 

Now, you can use ctrl+shift+c instead of CTRL+BREAK


Edit %APPDATA%Sublime Text 2PythonPython.sublime-build

Change content to:

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

change the "c:python27" part to any version of python you have in your system.


On Mac OS X, save your file with a .py extension. Press ⌘ + B. It runs in a window below.

在这里输入图像描述

链接地址: http://www.djcxy.com/p/77194.html

上一篇: Rails:可以检查一个字符串是否是二进制的?

下一篇: 如何从Sublime Text 2运行Python代码?