处理多个 Python 版本---不要独立运行 [英] Dealing with Multiple Python Versions--- do not run independently

查看:61
本文介绍了处理多个 Python 版本---不要独立运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的计算机(操作系统:Windows 7)上安装了 Python 2.7(我的首选版本)和 3.3(我的编程课程中使用的版本).直到某一时刻,他们独立工作得很好.

I have Python 2.7 (my preferred version) and 3.3 (version used in my Programming class) installed on my computer (OS: Windows 7). Until a certain point, they worked fine independently.

有一天,我的一个程序(在 3.3 中)出现错误并崩溃(它在命令提示符中,而不是在 IDLE 中).之后,我所有的 3.3 程序,当我尝试编辑它们(用 IDLE 编辑)或运行它们(在命令提示符下)时,它们作为 2.7 程序打开/运行.这是一个问题,因为 2.7 和 3.3 之间存在一些语法和其他差异.

One day, one of my programs (in 3.3), got an error and crashed (it was in the command prompt, not in IDLE). After that, all of my 3.3 programs, when I attempt to edit them (edit with IDLE) or run them (in the command prompt) they open/run as 2.7 programs. This is an issue because of some of the syntax and other differences between 2.7 and 3.3.

如何告诉我的 3.3 程序显式使用 Python 3.3?

How can I tell my 3.3 programs to explicitly use Python 3.3?

现在,我要做的是打开 IDLE(作为一个空白文件,而不是特定程序),然后在 IDLE 中使用 Open 选项.另外,用命令处理器运行程序是不可能的.

Right now, what I have to do is open IDLE (as a blank file, not a specific program), then use the Open option in IDLE. In addition, running the program with the command processor is out of the question.

我查了一下,看到了一些关于使用 #!/usr/bin/env 的信息,但我不确定如何使用它.Python 3.3 安装在以下文件夹中:C:\Python3.3(即文件路径).

I looked it up and saw something about using #!/usr/bin/env but I am unsure on how to use this. Python 3.3 is installed in the following folder: C:\Python3.3 (that's the file path).

谢谢!

推荐答案

你可以使用 shebang 行:

#! /usr/bin/env python2

对于 Python 2.x 脚本和:

for Python 2.x scripts and:

#! /usr/bin/env python3

用于 Python 3.x 脚本.您可以使用更具体的版本,例如 python3.3

for Python 3.x scripts. You can use more specific versions e.g., python3.3

您可以配置默认 Python 版本.

这篇关于处理多个 Python 版本---不要独立运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆