3

I'm new to python. I've installed both Python 3.2.2 for x64 and Python 2.7 for x86 on my 64-bit windows machine. I've got some python code that are coded for python 2.x versions. But every time I try to run them by double clicking it is interpreted by python 3.x.

How do I force them to use python version 2.7, may be using some directives or using a BATCH script?

Reekdeb Mal
  • 728
  • 1
  • 7
  • 13

4 Answers4

2

Going forward, 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, include the following line:

#!/usr/bin/env python3

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

#!/usr/bin/env python2

The #! part, called a shebang, indicates to Python Launcher which version of Python is desired. (It also indicates to UNIX that a program should be run with a particular interpreter instead of the shell.) The /usr/bin/env part helps locate the Python interpreter on your PATH when you run a program on UNIX. If you don't plan on using anything but Windows, you can leave it out:

#! python3

[or]

#! python2
Damian Yerrick
  • 4,602
  • 2
  • 26
  • 64
1

You could, e.g., associate the file extension .py2 with Python 2.7 and rename the main file (assuming you regard Python 3.2 as your default version).

Fred Foo
  • 355,277
  • 75
  • 744
  • 836
0

open a command line window, and use "c:\python27\python.exe" yourscript.py (or whatever path your python 2.7 appears to be installed in).

of course, you can put that line into a batch file and execute the batch.

also, you can put a shortcut to c:\python27\python.exe on your desktop and drop your script onto that shortcut every time you want to run it.

Adrien Plisson
  • 22,486
  • 6
  • 42
  • 73
-1

try editing PATH environment variable, use python 2.7 path and delete python 3.2.2

Abed Hawa
  • 1,372
  • 7
  • 18