在 Windows 上安装 Python 2.x 和 3.x 的同时使用较旧的 Python 2.x [英] Using older Python 2.x while having both Python 2.x and 3.x installed on Windows

查看:36
本文介绍了在 Windows 上安装 Python 2.x 和 3.x 的同时使用较旧的 Python 2.x的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Python 新手.我已经在我的 64 位 Windows 机器上安装了适用于 x64 的 Python 3.2.2 和适用于 x86 的 Python 2.7.我有一些为 python 2.x 版本编码的 python 代码.但是每次我尝试通过双击运行它们时,python 3.x 都会对其进行解释.

I'm new to python. I've installed both Python 3.2.2 for x64 and Python 2.7 for x86 on my 64-bit windows machine. I've got some python code that are coded for python 2.x versions. But every time I try to run them by double clicking it is interpreted by python 3.x.

我如何强制他们使用 Python 2.7 版,可能正在使用某些指令或使用 BATCH 脚本?

How do I force them to use python version 2.7, may be using some directives or using a BATCH script?

推荐答案

展望未来,解决方案是将 Python 3.2 升级到 3.3 或更高版本并使用 适用于 Windows 的 Python 启动器.

Going forward, the solution is to upgrade Python 3.2 to 3.3 or later and use the Python Launcher for Windows.

在每个 Python 3 程序的顶部,包括以下行:

At the top of each Python 3 program, include the following line:

#!/usr/bin/env python3

在每个 Python 2 程序的顶部,包括以下行:

At the top of each Python 2 program, include the following line:

#!/usr/bin/env python2

#! 部分,称为 shebang, 向 Python Launcher 指示所需的 Python 版本.(它还向 UNIX 表明程序应该使用特定的解释器而不是 shell 运行.)/usr/bin/env 部分有助于在 PATH 上定位 Python 解释器code> 当您在 UNIX 上运行程序时.如果你不打算使用 Windows 以外的任何东西,你可以不使用它:

The #! part, called a shebang, indicates to Python Launcher which version of Python is desired. (It also indicates to UNIX that a program should be run with a particular interpreter instead of the shell.) The /usr/bin/env part helps locate the Python interpreter on your PATH when you run a program on UNIX. If you don't plan on using anything but Windows, you can leave it out:

#! python3

[or]

#! python2

这篇关于在 Windows 上安装 Python 2.x 和 3.x 的同时使用较旧的 Python 2.x的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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