简体   繁体   English

如何在 sublime text 2 上运行 python 3.4?

[英]How do I run python 3.4 on sublime text 2?

This is what my python build looks like:这是我的python构建的样子:

{  
    "cmd": ["python", "-u", "$file"],  
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",  
    "selector": "source.python"    
}

I've read that I need to change what's in the "python" part of "cmd":, but I can't find what to change it to.我读过我需要更改“cmd”的“python”部分中的内容:,但我找不到要更改的内容。 I've seen one video where a guy made it look really easy by taking the path from the terminal.看过一个视频,其中一个人通过从终端走来使它看起来非常容易。 Others say to add a "path": blah blah blah.其他人说要添加一个“路径”:等等等等。 It always seems to be for Windows computers.它似乎总是适用于 Windows 计算机。

I've tried so many things and I really don't know what to change to make sublime text 2 to run python.我已经尝试了很多东西,但我真的不知道要更改什么才能使 sublime text 2 运行 python。 Also does it make a difference if I'm using a mac vs windows?如果我使用的是 mac 还是 windows,这也有区别吗?

cmd needs to be changed to the path of the python 3 executable. cmd需要更改为 python 3 可执行文件的路径。 By default, the installer places it in ~/Library/Frameworks/Python.framework/Versions/3.4/bin/python3 .默认情况下,安装程序会将它放在~/Library/Frameworks/Python.framework/Versions/3.4/bin/python3 So, if your mac username is Anthony , you will need to change your build like so:因此,如果您的 mac 用户名是Anthony ,您将需要像这样更改您的构建:

{  
    "cmd": ["/Users/Anthony/Library/Frameworks/Python.framework/Versions/3.4/bin/python3", "-u", "$file"],  
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",  
    "selector": "source.python"    
}

Note: When running python 3 from the terminal, you are able to use the shortcut command python3 .注意:从终端运行 python 3 时,您可以使用快捷命令python3 This is because an ALIAS was set up in your .bash_profile when python was installed.这是因为安装 python 时在 .bash_profile 中设置了 ALIAS。 However, Sublime Text doesn't read your .bash_profile, so you must specify the full path to python.但是,Sublime Text 不会读取您的 .bash_profile,因此您必须指定 python 的完整路径。

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

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