Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get VScode to run python 2.7.13 instead of python 3.6

I'm trying to use VScode to run some scripts using python 2.7.13 but it always seems to use python 3. First I set up 2 virtual environments. One for python 2 and one for python 3. this doesn't seem to effect VSCode. It always seems to use python 3. I know its using python 3 because I put the following 2 lines in my code:

aa=10
print aa

but I always get an error message associated with the print statement. I know if I use parenthesis in the print statement all works fine.

I also tried using the "Python: Select Interpreter" from the command palette in VSCode. This doesn't work either.

I am running on a Mac with High Sierra. I have the latest version of VScode, 1.23.

What am doing wrong? How do I get VScode to use python 2.

like image 773
Natsfan Avatar asked Dec 04 '22 20:12

Natsfan


2 Answers

  1. enter cmd+shft+p
  2. Python: Select Interpreter

  3. Enter your version
like image 109
Kayla Avatar answered Dec 06 '22 09:12

Kayla


I know there is already an accepted answer but wasn't helpful for me, so i'll add mine:

  1. Install both python2 and python3 with their installer, and remember to tick "add python to the path" during the installation
  2. As pointed out here from Bruno, go the the installation folder of python 2, and copy and paste "python.exe" and rename the copy into "python2.exe", do the same things for the python3 installation folder, copy and paste "python.exe" and rename it into "python3.exe"
  3. Into Visual studio code now you can run python 3 program with "python3 name_of_the_file.py", or python 2 program with "python2 name_of_the_file.py"

Otherwise try to follow this article didn't worked for me, but i din't read it carefully and probably did some mistakes

like image 31
Stefano Avatar answered Dec 06 '22 09:12

Stefano