7

I cannot seem to get Python3 to work when debugging it continues to use Python2. I've tried a few things but still am unable to get it work. I verified Python3s path is /usr/local/bin/python3 Everytime I run a script to by

import sys
print(sys.version)

I still get 2.7.10 python 3 is installed and work correctly.

I have this in my launch.json and settings.json (type and request are both grayed out for some reason in the launch.json)

 {
"name": "Python",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"program": "${file}",
"pythonPath": "/usr/local/bin/python3",
"debugOptions": [
    "WaitOnAbnormalExit",
    "WaitOnNormalExit",
    "RedirectOutput"
] }
2
  • I'm not very familiar with Visual Studio Code, but pythonPath would normally be the path to your python lib folder, not to your python executable? Commented Jun 5, 2017 at 4:46
  • How are you running the program from within VS Code? I have a debugging configuration set up to use the python binary within the virtualenv I have in a separate folder. However, if I run which python in a terminal (even within Code) it'll point me to my /usr/local/bin/python. Commented Sep 5, 2017 at 5:49

4 Answers 4

10

To select a specific python interpreter, invoke the Python: Select Interpreter command from the Command Palette (⇧⌘P).

enter image description here

This will update your .vscode/settings.json file:

{
    "python.pythonPath": "/usr/local/bin/python3"
}

You should then be able to debug using python 3 interpreter or any other python interpreter is available on your machine.

Sign up to request clarification or add additional context in comments.

2 Comments

the problems is that in the menu the python3 does not appear even if it is installed into the system.
if you installed python3 in your system and it isn't showing up, maybe it means its not in your PATH environment variable. Have you checked it?
1

if you use "code runner",you can try to open user settings with command palette.

{
    "code-runner.executorMap": {
        "python": "python3"
    }
}

it's work for me.

Comments

0

This is not an answer, but my rep won't allow a comment: For me your proposed solution worked just fine. Here some troubleshooting:

  • Did you change the original launch.json entry? Then you probably need to reload it, which should happen automatically, but restarting VSCode will do that for sure.
  • Also, I would recommend using the "Add Configuration" button, then choose "python", and edit the name in the new entry (from "Python" to "Python3") as not to clash with the old python entry, as well as change the "pythonPath" key's value from "${config:python.pythonPath}" to "/usr/local/bin/python3"

To use this config, select in the Debug dropdown box.

Comments

0

What worked for me is adding the following to User Settings:

{
    "python.pythonPath": "/usr/local/bin/python3"
}

1 Comment

python.pythonPath should point to the path of the python interpreter you want to use in vscode to debug and run python scripts. in my case, it was /usr/local/bin/python3 since i used homebrew to install python 3.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.