首页 > 代码库 > sublime text中用python3运行文件
sublime text中用python3运行文件
sublime text中用python3运行文件
在sublime text中可以使用快捷键cmd + b
(windows是CTRL + b
)快速运行一个python文件,sublime会直接调用系统默认python运行文件,并在下面的框里弹出结果。
如果我们想要使用自己的python版本,如python3或者其他第三方python包(如本人使用的anaconda)要怎么办呢?
sublime使用cmd+b
的操作叫做build
,在Tools -> Build System
中可以看到系统默认支持的类型,包括C++
、Java
等各种,默认选择的是Automatic
,系统会根据文件扩展名自动选择合适的Build方法。
操作方法
- 要使用自定义达到方法,选择下面的
New Build System...
,会弹出一个后缀为sublime-build
的文件。 - 在打开的文件中填写如下内容:
然后保存文件名为{ "cmd": ["/usr/local/bin/python3", "-u", "$file"], "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)", "selector": "source.python" }
python3.sublime-build
,文件会自动保存到sublime的自定义文件夹中,mac下默认是~/Library/Application Support/Sublime Text 2/Packages/User
- 重新进入刚才的
Build System
选项卡中,会发现下面增加了一个python3,选择该项。 - 再按
cmd+b
运行文件时,sublime就会用python3来运行该文件了。因为这个print
语句不符合python3语法所以报错。
sublime text中用python3运行文件
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。