如何从SublimeText2运⾏Python 代码?
本⽂翻译⾃:
I want to set up a complete Python IDE in Sublime Text 2. 我想在Sublime Text 2中设置完整的Python IDE。我想在Sublime Text 2中设置完整的Python IDE。I want to know how to run the Python code from within the editor. 我想知道如何从编辑器中运⾏Python代码。我想知道如何从编辑器中运⾏Python代码。 Is it done using build system? 使⽤构建系统完成吗?使⽤构建系统完成吗? How do I do it ? 我该怎么做 ?我该怎么做 ?
#1楼
#2楼
I had the same problem. 我有同样的问题。我有同样的问题。 You probably haven't saved the file yet. 您可能尚未保存⽂件。您可能尚未保存⽂件。 Make sure to save your code with .py extension and it should work. 确保使⽤.py扩展名保存您的代码,并且该代码应该可以⼯作。确保使⽤.py扩展名保存您的代码,并且该代码应该可以⼯作。#3楼
您可以使⽤ (⾸先需要安装 )。
#4楼
I solved this problem : 我解决了这个问题:我解决了这个问题:
Open the exec.py file, near line 41-42, the code should look like this : 打开第41-42⾏附近的打开第41-42⾏附近的exec.py ⽂件,代码应如下所⽰:then delete it or edit it as : 然后将其删除或编辑为:然后将其删除或编辑为:
#5楼
To RUN press Ctrl B (answer by ) 要运⾏,请按Ctrl B (按回答)要运⾏,请按Ctrl B (按回答)But when Ctrl B does not work , Sublime Text probably can't find the Python Interpreter. 但是,当但是,当Ctrl B 不起作⽤时,Sublime Text可能不到Python解释器。时,Sublime Text可能不到Python解释器。 When trying to run your program, see the log and find the reference to Python in path. 尝试运⾏程序时,请查看⽇志并在路径中到对Python的引⽤。尝试运⾏程序时,请查看⽇志并在路径中到对Python的引⽤。
> Preferences –> Browse Packages –> Default
1
for k, v in proc_env.iteritems():2 proc_env[k] = pandvars(v).filesystemencoding())
1try: 2
for k, v in proc_env.iteritems():3 proc_env[k] = pandvars(v).filesystemencoding())4
except:5 print 'foobar'
1
[cmd: [u'python', u'-u', u'C:\\scripts\\test.py']]2[path: ...;C:\Python27 32bit;...]
sublime text3安装教程The point is that it tries to run python via command line, the cmd looks like: 关键是它试图通过命令⾏运⾏python,cmd如下关键是它试图通过命令⾏运⾏python,cmd如下所⽰:
If you can't run python from cmd, Sublime Text can't too. 如果您⽆法从cmd运⾏python,那么Sublime Text也不会。如果您⽆法从cmd运⾏python,那么Sublime Text也不会。 (Try it yourself in cmd, type python in it and run it, python commandline should appear) (在cmd中⾃⼰尝试,在其中键⼊(在cmd中⾃⼰尝试,在其中键⼊python并运⾏它,应该显⽰python命令⾏)
SOLUTION 解
You can either change the Sublime Text build formula or the System %PATH% . 您可以更改Sublime Text构建公式或System 您可以更改Sublime Text构建公式或System %PATH% 。
To set your %PATH% : 设置设置%PATH% :
: * You will need to restart your editor to load new %PATH% * * 您将需要重新启动编辑器以加载新的%PATH%
Run Command Line* and enter this command: *needs to be run as administrator 运⾏命令⾏*,然后输⼊以下命令: 运⾏命令⾏*,然后输⼊以下命令: *需要以管理员⾝份运⾏
SETX /M PATH "%PATH%;<python_folder>"
for example: SETX /M PATH "%PATH%;C:\\Python27;C:\\Python27\\Scripts" 例如: 例如: SETX /M PATH "%PATH%;C:\\Python27;C:\\Python27\\Scripts"
OR manually: (preferable) 或⼿动:(⾸选)或⼿动:(⾸选)
Add ;C:\\Python27;C:\\Python27\\Scripts at the end of the string. 在字符串末尾添加在字符串末尾添加;C:\\Python27;C:\\Python27\\Scripts 。
。 To set the interpreter's path without messing with System %PATH% see this answer by . 要设置解释器的路径⽽不弄乱要设置解释器的路径⽽不弄乱System %PATH%请参阅答案。
#6楼On Mac OS X, save your file with a .py extension. 在Mac OS X上,以.py扩展名保存⽂件。在Mac OS X上,以.py扩展名保存⽂件。 Press
⌘ + B . 按按⌘ + B 。 It runs in a window below. 它在下⾯的窗⼝中运⾏。它在下⾯的窗⼝中运⾏。python -u C:\scripts\test.py
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论