Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
454 views
in Technique[技术] by (71.8m points)

windows - Using multiple versions of Python

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.

For Example: if I type F:Python33python33.exe test1.py, it will run with 3.3 and work fine, but if I type F:Python27python27.exe test1.py it gives this error:

File "F:PYTHON33LIBsite.py", line 173
    file=sys.stderr)
        ^
SyntaxError: invalid syntax

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Google search results have returned a few useful resources that answer your problem.

Python Docs

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.

The first option would be to include your python version in the file you wish to execute using something along the lines of

#! python
Your code here

To execute in Python 2, or

#! python3
Your code here

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.

StackExchange Sites

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

Or for Ubuntu 13: Ubuntu 13.04 Install and running Python 3 at the same time than Python 2.7.x

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...