Using multiple versions of Python

Viewed 23816

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:\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

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.

7 Answers

You will get issue if multipler version of python is set

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

To fix this issue remove previous version python set in system environment variable enter image description here

Setting the PYTHONPATH environment variable to nothing fixed this issue for me.

I received the same error when I was running my python file using python filename.py my PYTHONPATH was set to use python3

I fixed it by using the below command to run my file

python3 filename.py
Related