EditRunning files with Python3 in sublime text
In sublime text you cancmd + bquickly run a python file using the shortcut key (Windows YesCTRL + b), and Sublime will directly invoke the system default Python run file and pop up the results in the box below.
What if we want to use our own Python version, such as Python3 or other third-party python packages (such as the one I use anaconda)?
Sublime Usecmd+bOperation is calledbuildInTools -> Build SystemYou can see the types that the system supports by default, includingC++、JavaAnd so on, the default choice isAutomatic, the appropriate build method is automatically selected based on the file name extension.
Operation method
-
- To use the custom Reach method, select the followingNew Build System..., which will pop up asublime-buildfile with the suffix.
- In the open file, fill in the following content:
{
"cmd": ["/usr/local/bin/python3", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python" }
Then save the file name aspython3.sublime-build, the file is automatically saved to a custom folder in sublime, and the default is~/Library/Application Support/Sublime Text 2/Packages/User
-
- Re-enter theBuild Systemtab, you will find a python3 added below, select the item.
-
- cmd+bwhen you press the run file again, Sublime will run the file with Python3. Because thisprintstatement does not conform to PYTHON3 syntax, it is an error.
Sublime text in Python3 run file