I'm running VS Code 1.33.1 on macOS Sierra (10.12.6). When I run a simple Python program like the following, VS Code uses Python 2.7 as installed on my Mac rather than Python 3 which I installed using Homebrew.
# show-python-version.py
import sys
print(sys.version)
Here's the output as displayed in the VS Code Output window:
[Running] python -u "/Users/smith/Documents/Programming/Python/Examples/show-python-version.py"
2.7.15 (default, May 1 2018, 16:44:37)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)]
[Done] exited with code=0 in 0.032 seconds
As you can see, I'm getting version 2.7.15 because it's calling "python" instead of "python3", but I don't know how to get it to use python3. Here are all the things I've done to try to fix this problem:
I've ensure that none of my virtual environments that use Python 2.7 are running when I issue the "code ." command in the Examples directory.
I installed Python 3 using Homebrew so I opened the Command Pallette (shift + cmd + p), typed in "Python: Select Interpreter", and confirmed that it's using my Homebrew version: current: /usr/local/bin/python3.
I checked VS Code's Settings, searched for "python.pythonPath" and confirmed that it's the same as the interpreter path shown in step 2 above.
I also examined the file Examples/.vscode/settings.json to confirm the interpreter path there too:
{
"python.pythonPath": "/usr/local/bin/python3"
}
I've restarted VS Code to no avail.
I have these extensions installed:
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
It's may be related to my path which looks like the following since both python and python3 are in /usr/local/bin:
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:....
What am I doing wrong?
It's because of the code runner extension. Add this "code-runner.executorMap.python": "python3 -u" to your settings.json and that should change the python version for when it runs code to python3 instead of python2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With