python - 使用多个版本的 Python

标签 python windows python-2.7 python-3.x

我的计算机上同时安装了 Python 3.3 和 Python 2.7。 python 3.3 工作正常,但是当我尝试使用 python 2.7 运行某些东西时,它仍然引用 python 3.3。

例如:如果我键入 F:\Python33\python33.exe test1.py,它将使用 3.3 运行并且工作正常,但如果我键入 F:\Python27\python27 .exe test1.py 它给出了这个错误:

File "F:\PYTHON33\LIB\site.py", line 173
    file=sys.stderr)
        ^
SyntaxError: invalid syntax

注意:我已将 Python 2.7 和 3.3 .exe 分别重命名为 python27.exe 和 python33.exe。

如有任何帮助,我们将不胜感激。

最佳答案

Google 搜索结果返回了一些有用的资源来解决您的问题。

Python 文档

Python 文档 (http://docs.python.org/3.3/using/windows.html#python-launcher-for-windows) 提供了在同一台机器上运行多个版本的快速概览。

第一个选项是将您的 Python 版本包含在您希望使用类似以下内容执行的文件中

#! python
Your code here

要在 Python 2 中执行,或者

#! python3
Your code here

用于在您的 Python 3 版本中运行代码。然后您只需使用“python yourscript.py”,python 版本将由 Python 脚本指定。

StackExchange 网站

还有多个其他问题可能会解决您面临的问题:
How to install both Python 2.x and Python 3.x in Windows 7

或者对于 Ubuntu 13:Ubuntu 13.04 Install and running Python 3 at the same time than Python 2.7.x

或者对于使用 Homebrew 的 Mac:How can I use Homebrew to install both Python 2 and 3 on Mac?
以及没有 Homebrew 的 Mac 视频引用:http://www.youtube.com/watch?v=c9LlK2iu7OA

关于python - 使用多个版本的 Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20555517/

相关文章:

python - 从 Django shell 上传图像

python - String.strip() 重要性

Python 多处理不使用超过 1 个核心

c++ - 为什么在使用 Unix 和 Windows 系统的 C++ 中声明指针时会出现这种行为?

python - 将 Json 转换为 SQL 表

c# - 将 C# 控制台应用程序转换为服务(Main 方法不起作用)

windows - 在Windows中访问音频

python - 如何从 Python 中的 RRULE 中查找频率?

python - 如何在 Python 2.7 中线程化多个子进程实例?

python - 无法使用 python3 在 numpy 中导入名称 'multiarray'