简体   繁体   中英

VS Code Python Extension says that my Python Path is invalid

In VS Code on Ubuntu 20.04, when I press F5 to run a python script, I get:

"The Python path in your debug configuration is invalid."

Here is the relevant part of my launch.json:

   "configurations": [
        {
            "name": "Python: Current File (Integrated Terminal)",
            "type": "python",
            "python": "/home/ian/anaconda3/bin/python3",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        },

I have the correct Debug configutation set:

在此处输入图像描述

When I run /home/ian/anaconda3/bin/python3 it works fine.

For what it's worth, in the integrated terminal both

which python

and

which python3

Return /home/ian/anaconda3/bin/python (3)

How can I get VS Code to run python?

You could try this configuration, it works for me:

    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": true
        }
    ]

PS: As Omroth said, I have selected an interpreter before, so I don't need to specify python command in launch.json .

If you need to choose Python interpreter, use shortcuts "Ctrl+Shift+P" and type "Python: Select interpreter".

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM