Home >Development Tools >sublime >Simple tutorial for configuring Python interpreter in Sublime Text editor
The day before yesterday, I met a friend on WeChat who asked me a question about configuring the Python interpreter for Sublime text. He may be a beginner and doesn’t know much about this aspect. He wanted to use shortcut keys but it was in vain because he lacked Python. Interpreter, pressing the shortcut key Ctrl B directly will not get the desired result.
In view of this, if anyone wants to use Sublime to run Python programs, then configuring the Python interpreter is an essential step. Here, the editor has compiled this step-by-step tutorial, hoping to pave the way for newcomers.
The following tutorial column will introduce to you how to configure the Python interpreter in the Sublime Text editor: 1. First open Sublime, as shown in the figure below, and then select the "Preferences" tab. 2. Click the first option "Browse Packages...", and then the system will automatically locate the Sublime installation package directory.
3. Then the folder interface as shown below will pop up.
4. Find the Python folder in this pile of folders, as shown in the figure below, then enter the folder and find the Python.sublime-build file.
5. Open the file in Sublime, as shown in the figure below.
{ "cmd":["python.exe","-u", "$file"], "path":"C:\Python34", "file_regex": "^[ ]File"(...?)", line ([0-9]*)", "encoding": "gbk", "selector": "source.python" }
The content shown in the picture is the content after I updated it. The original content is not so rich. Mainly to change two places, one is to add the Python interpreter path, and the second is to add the encoding part. Generally, the encoding chosen is utf-8 or gbk, and some use cp936, mainly to prevent Sublime Text from reporting [Decode error - output not utf-8] error. Generally speaking, if we do not set the encoding, once the output is in a language other than English, encoding problems will occur, which is a headache. Generally, it is not a big problem if you try several encodings.
6. After changing the Python.sublime-build file, press the shortcut key Ctrl S to save it. Then open a Python file at will, and then click the tab ToolsàBuildSystemàPython in Sublime, as shown in the figure below. The whole process is equivalent to completing the perfect "connection" between Sublime and the Python interpreter.
7. Now you can use the shortcut key Ctrl B or add the tab ToolsàBuild in sequence, as shown in the figure below, and then you can run the current Python file. The effect is as shown in the figure below. The output part of the file is below Sublime, usually a gray rectangular part.
8. At this point, the problem of configuring the Python interpreter in Sublime and the [Decode error - output not utf-8] error has been successfully solved.
I hope that when future friends encounter this problem again, they can avoid detours. Although the editor is currently using Sublime Text 2, the configuration method of Sublime Text 3 is exactly the same as Sublime Text 2, so I won’t go into details.
The above is the detailed content of Simple tutorial for configuring Python interpreter in Sublime Text editor. For more information, please follow other related articles on the PHP Chinese website!