使用 Sublime Text 3 设置 Python 3 构建系统 [英] Set up Python 3 build system with Sublime Text 3
问题描述
我想配置 Sublime Text 3 来构建 Python 3,但我似乎不明白构建是如何工作的.许多教程都告诉我制作一个包含代码的构建文件,例如:
I want to configure Sublime Text 3 to build Python 3, but I don't seem to understand how the builds work. Many tutorials have told me to make a build file containing code such as:
{
'cmd': ['/usr/bin/python3', '-u', '$file'],
'file_regex': '^[ ]*File "(…*?)", line ([0-9]*)',
'selector': 'source.python'
}
并将其保存为名为 Python.sublime-build
或 python3.sublime-build
的文件(我发现的大部分信息都是相互矛盾的).一个教程建议在 ST3 Packages 文件夹中创建一个名为 Python
的新文件夹并将构建文件添加到其中,而其他教程建议将其保留在名为 User
的文件夹中.
and save it as a file called Python.sublime-build
or python3.sublime-build
(much of the information I found was conflicting). One tutorial suggested creating a new folder in the ST3 Packages folder called Python
and add the build file in there, whilst other tutorials suggested leaving it in the folder called User
.
一个教程解释了我必须如何更改操作系统上的环境变量 path
才能使其工作.这似乎也没有帮助.
One tutorial explained how I had to change the Environment Variable path
on my operating system to get it to work. That didn't seem to help either.
我在 Packages
中添加了一个文件夹 Python
(因为它不存在)并添加到一个名为 Python.sublime_build
的构建文件中代码>,其中仅包含我在上面发布的代码.现在,当我尝试运行 Sublime Text 时,它给了我这个错误:
I added a folder Python
to Packages
(since it wasn't there already) and added in a build file with the name Python.sublime_build
which featured only the code I posted above in it. Now when I attempt to run Sublime Text it gives me this error:
Error trying to parse build system:
Expected value in Packages\Python\Python.sublime-build:2:5
推荐答案
你收到错误的原因是你有一个 Unix 风格的 python
可执行文件路径,当你运行 Windows.将 /usr/bin/python3
更改为 C:/Python32/python.exe
(确保使用正斜杠 /
而不是 Windows-样式反斜杠 \
).进行此更改后,您应该一切准备就绪.
The reason you're getting the error is that you have a Unix-style path to the python
executable, when you're running Windows. Change /usr/bin/python3
to C:/Python32/python.exe
(make sure you use the forward slashes /
and not Windows-style back slashes \
). Once you make this change, you should be all set.
此外,您需要将单引号 '
更改为双引号 "
,如下所示:
Also, you need to change the single quotes '
to double quotes "
like so:
{
"cmd": ["c:/Python32/python.exe", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
.sublime-build
文件需要是有效的 JSON,它要求字符串用双引号括起来,而不是单身.
The .sublime-build
file needs to be valid JSON, which requires strings be wrapped in double quotes, not single.
这篇关于使用 Sublime Text 3 设置 Python 3 构建系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!