Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run programs in python2 and python3

Tags:

python

I have python 2.6.6 and python 3.1.3 currently installed on my machine (Windows Vista 64 bit) My path variable includes the directory of both versions. How can I specify which python I want to run a program in. For instance, if I want to run a program in python 3, it works but if I want to run a different program in python2 I get a syntax error. So how can I run a python 2 program in the cmd?

Typing python in my command line, python 3.1.3 is the only one that shows up.

like image 783
kachilous Avatar asked Feb 09 '11 02:02

kachilous


People also ask

How do I run a Python 2 program in Python 3?

We can convert Python2 scripts to Python3 scripts by using 2to3 module. It changes Python2 syntax to Python3 syntax. We can change all the files in a particular folder from python2 to python3.

Can I run Python 2 and 3 on the same computer Windows?

you can install both python 2 and python 3 in your machine but you can not use both in single code editor in same time. To use both at same time you have to open one IDEs with python 2 and another IDEs with python 3.

Can a program written in Python 3 run in Python 2?

Python 2.6 includes many capabilities that make it easier to write code that works on both 2.6 and 3. As a result, you can program in Python 2 but using certain Python 3 extensions... and the resulting code works on both.

Is Python 2 and 3 backwards compatible?

Python 3 is not backwards compatible with Python 2, so your code may need to be adapted. Please start migrating your existing your existing Python 2 code to Python 3. Python 2 series End Of Life is set to 1st of January 2020.


1 Answers

Instead of just typing "python" on the command line, use the full path the python.exe that you want to run: FULL_PATH_TO_PYTHON_2.6.6\python.exe or FULL_PATH_TO_PYTHON_3.1.3\python.exe should distinguish between the two.

like image 130
duffymo Avatar answered Oct 20 '22 23:10

duffymo