简体   繁体   English

如何指定升华文本是我想使用python2.7还是python3运行python代码

[英]How to specify to sublime text whether I want to run my python code with python2.7 or python3

I am using the script package to run my python code in sublime text but it has no way to specify whether to run it with python3 or 2, and since all of my libraries are in python3 I need it to run with it too, is there a way to do this or do I just have to uninstall python2.7 all together to coerce it to run with python3. 我正在使用脚本包以崇高的文本格式运行我的python代码,但是它无法指定是使用python3还是2运行它,并且由于我所有的库都在python3中,因此我也需要使用它来运行它一种执行此操作的方法,或者我只需要一起卸载python2.7即可强制它与python3一起运行。 Thanks 谢谢

Install a plug-in called Anaconda for sublime using package control. 使用程序包控制安装名为Anaconda的插件以实现Sublime。 It'll turn your text editor into IDE. 它将把您的文本编辑器变成IDE。 With Anaconda you can manually set which python interpreter to use using project settings. 使用Anaconda,您可以使用项目设置手动设置要使用的python解释器。 You can even set it to custom Python Virtualenv. 您甚至可以将其设置为自定义Python Virtualenv。

For ref: 对于参考:

Setting up Sublime Text 3 for Full Stack Python Development 为全栈Python开发设置Sublime Text 3

Configure Anaconda the Right Way 正确配置Anaconda

On Windows, you dont need create a new build system or specify the absolute path. 在Windows上,您不需要创建新的构建系统或指定绝对路径。 Edit already existing python build system. 编辑已经存在的python构建系统。

In SublimeText\\Data\\Packages\\ create folder Python -> like this SublimeText\\Data\\Packages\\Python\\ In this folder, create a file Python.sublime-build , it will overwrite the existing python build system. SublimeText\\Data\\Packages\\创建文件夹Python >这样的SublimeText\\Data\\Packages\\Python\\在此文件夹中创建一个文件Python.sublime-build ,它将覆盖现有的python构建系统。

In this file write (python launcher documentation) 在此文件中编写(python启动器文档)

{
    "shell_cmd": "py -u \"$file\"",
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python",
    "env": {"PYTHONIOENCODING": "utf-8"},
}

For choosing version of python interpretator, in the first line of your scripts write (shebang lines) 为了选择python解释器的版本,请在脚本的第一行中编写(shebang行)

#! python #! python or #! python3 #! python#! python3 #! python3

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

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