Reputation: 4847
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.
Upvotes: 8
Views: 43588
Reputation: 3
if you download Code Runner
in extensions the default run command is python
and you may modify it by opening the setting and searching for code-runner.executorMap
and hit Edit in settings.json
you may see following
"python": "python",
by changing the right-hand side you can easily switch to python2
or pyhton3
Upvotes: 0
Reputation: 61
I know there is already an accepted answer but wasn't helpful for me, so i'll add mine:
Otherwise try to follow this article didn't worked for me, but i din't read it carefully and probably did some mistakes
Upvotes: 3
Reputation: 36
firstly, in vscode's terminal:
suyichengdeMacBook-Air:alltest suyicheng$ python -V
Python 2.7.10
suyichengdeMacBook-Air:alltest suyicheng$ python3 -V
Python 3.6.2
In my vscode, I can use python or python3, maybe in your computer ,it will be python2.7 or others.
then, setting, search 'python.pythonPath'.
if I want to use python3.X,I set
"python.pythonPath": "python3"
then:
File "/Users/suyicheng/bs/alltest/test.py", line 2
print 22
^
SyntaxError: Missing parentheses in call to 'print'
And when I set :
"python.pythonPath": "python",
It works~
Hope my poor English can help you~
Upvotes: 2