Using older Python 2.x while using Python 2.x and 3.x on Windows

I am new to python. I installed both Python 3.2.2 for x64 and Python 2.7 for x86 on my 64-bit Windows computer. I have python code that is encoded for python 2.x versions. But every time I try to start them with a double click, this is interpreted by python 3.x.

How to get them to use python version 2.7, can some directives be used or use a BATCH script?

+3
source share
4 answers

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

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

#!/usr/bin/env python3 

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

 #!/usr/bin/env python2 

Part #! , called shebang , points to the Python Launcher which version of Python is required. (He also tells UNIX that the program should run with a specific interpreter instead of a shell.) The /usr/bin/env helps you find the Python interpreter on your PATH when you run the program on UNIX. If you do not plan to use anything other than Windows, you can leave it:

 #! python3 [or] #! python2 
+2
source

You can, for example, associate the .py2 file .py2 with Python 2.7 and rename the main file (assuming Python 3.2 is considered the default version).

+1
source

open a command prompt window and use "c:\python27\python.exe" yourscript.py (or any other path in which your python 2.7 will be installed).

Of course, you can put this line in a batch file and execute the package.

you can also put a shortcut on c:\python27\python.exe on your desktop and move the script to this shortcut every time you want to run it.

0
source

try changing your PATH environment variable, use python 2.7 path and remove python 3.2.2

-one
source

All Articles