简体   繁体   English

如何在Sublime text 2 python中运行代码

[英]How to run code in Sublime text 2 python

I recently installed sublime text 2 to try it out before I decide to get sublime text 3 but I can't properly run any code from it. 我最近安装了sublime text 2,在我决定获得sublime text 3之前试用它,但我无法正确运行任何代码。 I've hit Ctrl + B and I get an output like this. 我按下了Ctrl + B,得到了这样的输出。

[Error 2] The system cannot find the file specified
[cmd:  [u'python', u'-u', u'C:\\Users\\Jeff\\Desktop\\Personal codes\\print.py']]
[dir:  C:\Users\Jeff\Desktop\Personal codes]
[path: C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files         (x86)\Common Files\Microsoft Shared\Windows Live;C:\Program Files(x86)\AMD APP\bin\x86_64;C:\Program Files (x86)\AMD APP\bin\x86;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files (x86)\Windows Live\Shared]
[Finished]

I've looked in my roaming folder and found sublime text 2 because another post mentioned editing a file in the python folder there but no such folder exists in Roaming\\Sublime Text 2 all I have is Installed Packages, Packages, Pristine Packages and Settings. 我查看了我的漫游文件夹并找到了崇高文本2,因为另一篇文章提到在python文件夹中编辑文件但漫游\\ Sublime Text 2中没有这样的文件夹我所拥有的是安装包,包,Pristine包和设置。 Am I missing something or is it something obvious that I should know? 我错过了一些东西,还是我应该知道的明显的东西?

Instead of adding python to the path, I prefer simply specifying the full path to python in the sublime build. 我更喜欢在sublime构建中指定python的完整路径,而不是将python添加到路径中。 Python.exe is probably installed in one of these (or something similar) Python.exe可能安装在其中一个(或类似的东西)

C:/Python
C:/Program Files/Python
C:/Program Files (x86)/Python
etc...

Once you found it (lets say its in C:\\Program Files (x86)\\Python27) edit the sublime_build for python. 一旦找到它(假设它在C:\\ Program Files(x86)\\ Python27中),编辑pyl的sublime_build。 Here is the build I use: 这是我使用的构建:

{
    "cmd": ["C:\\Program Files (x86)\\Python27\\python.exe","-u","$file"],
    "selector": "source.python"

}

for me, this file is in 对我来说,这个文件是在

Sublime Text\Data\Packages\Python\Python.sublime-build

Windows is unable to find your python installation. Windows无法找到您的python安装。 When you run a command like: 当您运行如下命令时:

python <your_file.py>

the first python tells your system to find wherever your python binary is and try to run some command by that name. 第一个python告诉你的系统找到你的python二进制文件的位置,并尝试用该名称运行一些命令。 By looking over the path that was echoed, it doesn't look like you actually have your python binary on your system path. 通过查看回显的路径,看起来你的系统路径上实际上没有你的python二进制文件。

If you're uncertain as to how to add python to your path , check out this superuser question: https://superuser.com/questions/143119/how-to-add-python-to-the-windows-path 如果您不确定如何将python添加到path ,请查看此超级用户问题: https//superuser.com/questions/143119/how-to-add-python-to-the-windows-path

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM