debugging python in visual studio , multiple versions of python

I am new to Python. I have an python project, I need to debug. The program was developed and run with an older version of python (2.7 or earlier) .
I have python 3.7 installed in my windows 7.
I want to install python 2 alongside python 3 and debug the program using python 2.

How can i achieve this?
is virtual env used for this?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Just download python2 and install it. Windows and it's python launcher py.exe will then be aware that you installed python2 and python3 on your PC.

from command line ( you can choose the python version by typing.

py -2  

Open in new window

for python2

py -3

Open in new window

for python3

Another way to specify on a per script base which version of python to run is to add following as first line of your python script.

#!/usr/bin/env python2

Open in new window

#!/usr/bin/env python3

Open in new window

virtualenv is a package that allows you to have different virtual environments on your machine.

A virtual environment can only be based on a python version that has been installed on your host.
So if you did not install python2 you can not create a python2 virtual envronment.

Within each environment you can install different python packages, (or different versions of it)

This would allow you for example to test if some code works with django 1.11 (you created one virtualenv in which you installed django 1.11)
and if it works as well with django 2.1 (another virtualenv in which you installed django 2.1)

If you have python2 and python3 installed on your host you can have virtualenvs with either poython2 or python3 as a abase.
NorieAnalyst Assistant Commented:
When you first open the file in Visual Studio Code you should be asked to select an interpreter if you haven't selected one previously.

If you have set the interpreter previously you can change it by opening the Command Palette (Ctrl+Shift+P), selecting Python :Select Interpreter and then selecting the version you want to use.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
I overlooked, that you specifically asked for a solution for visual studio.

My answers assumed you're not using an IDE, that you want to be able to select the python version to be used, when clicking on the python file.
So not really the answer you were looking for.

If you use an IDE, then almost every IDE has somewhere settings to choose the python interpreter on a project basis or as global settings.

Norie gave you the answer for Visual Studio Code, For other IDEs (e.g. PyCharm) there will be somewhere similar settings.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows OS

From novice to tech pro — start learning today.