使用多个版本的 Python [英] Using multiple versions of Python
问题描述
我的计算机上安装了 Python 3.3 和 Python 2.7.python 3.3 工作正常,但是当我尝试使用 python 2.7 运行某些东西时,它仍然引用 python 3.3.
I have both Python 3.3 and Python 2.7 installed on my computer. The python 3.3 works fine, but when I try to run something using python 2.7, it is still referencing python 3.3.
例如:如果我输入 F:\Python33\python33.exe test1.py
,它将以 3.3 运行并且工作正常,但如果我输入 F:\Python27\python27.exe test1.py
它给出了这个错误:
For Example: if I type F:\Python33\python33.exe test1.py
, it will run with 3.3 and work fine, but if I type F:\Python27\python27.exe test1.py
it gives this error:
File "F:\PYTHON33\LIB\site.py", line 173
file=sys.stderr)
^
SyntaxError: invalid syntax
注意:我已将 Python 2.7 和 3.3 .exe 分别重命名为 python27.exe 和 python33.exe.
Note: I have renamed the Python 2.7 and 3.3 .exe's to python27.exe and python33.exe respectively.
任何帮助将不胜感激,谢谢.
Any help would be appreciated, Thank you.
推荐答案
Google 搜索结果返回了一些有用的资源,可以解答您的问题.
Google search results have returned a few useful resources that answer your problem.
Python 文档(http://docs.python.org/3.3/using/windows.html#python-launcher-for-windows) 提供了在同一台机器上运行多个版本的快速概览.
The Python Documentation (http://docs.python.org/3.3/using/windows.html#python-launcher-for-windows) gives a quick overview for running multiple versions on the same machine.
第一个选项是将您的 Python 版本包含在您希望执行的文件中,使用类似的内容
The first option would be to include your python version in the file you wish to execute using something along the lines of
#!蟒蛇
您的代码在这里
在 Python 2 中执行,或
To execute in Python 2, or
#!python3
您的代码在这里
用于在您的 Python 3 版本中运行代码.然后您只需使用python yourscript.py",python 版本将由 Python 脚本指定.
For running the code in your Python 3 version. Then you would simply use "python yourscript.py" and the python version would be specified by the Python script.
还有多个其他问题可以解决您面临的问题:
如何安装两者Windows 7 中的 Python 2.x 和 Python 3.x
There are multiple other questions which may address the problem you are facing:
How to install both Python 2.x and Python 3.x in Windows 7
或者对于 Ubuntu 13:Ubuntu 13.04 与 Python 2.7.x 同时安装和运行 Python 3
Or for Ubuntu 13: Ubuntu 13.04 Install and running Python 3 at the same time than Python 2.7.x
或者对于使用 Homebrew 的 Mac:如何使用 Homebrew 在 Mac 上安装 Python 2 和 3?
还有一个没有 Homebrew 的 Mac 视频参考:http://www.youtube.com/watch?v=c9LlK2iu7OA
Or for Mac using Homebrew: How can I use Homebrew to install both Python 2 and 3 on Mac?
And a video reference for Mac without Homebrew: http://www.youtube.com/watch?v=c9LlK2iu7OA
这篇关于使用多个版本的 Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!