gpt4 book ai didi

python - 可以在 Sublime Text 3 构建系统中在 python 2 和 3 之间切换吗? ( window )

转载 作者:太空宇宙 更新时间:2023-11-03 14:09:33 28 4
gpt4 key购买 nike

我目前所有的编码都是在 python 3 中进行的,我是通过 Anaconda 包安装的。但是我需要在 python 2 中同时处理一些代码。有没有一种方法可以在 Sublime 中添加一个构建系统,这样我就可以在两者之间流畅地切换?我同时安装了 python 2 和 3,但是看不到一种简单地编辑构建系统以在两种语言之间切换的方法。我为 python 3 使用的构建系统是:

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

非常感谢!

最佳答案

指定 Python 版本的绝对路径。例如,如果 Python 版本 3 位于 /usr/bin/python3 而 Python 版本 2 位于 /usr/bin/python2:

Python 3 构建配置:

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

Python 2 构建配置:

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

通过which找到Python的位置:

$ which python
/usr/bin/python

$ which python3
/usr/bin/python3

$ which python2
/usr/bin/python2

参见 Build system of Sublime Text 3 executes a different version of PHP , 是同一个委托(delegate)人。

关于python - 可以在 Sublime Text 3 构建系统中在 python 2 和 3 之间切换吗? ( window ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40024713/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com