简体   繁体   中英

Visual Studio Code (VSC) python bash: syntax error near unexpected token `&'

I have a problem, when running a python file, the &symbol appears in the bash. how do I remove it when I start the program? problem

Sorry for the late.

Take adventage of terminal.integrated.shell.windows instead of terminal.integrated.defaultProfile.windows for now.

You can take this as a workaround and wait for the next stable release of VSCode. On the VSCode insiders it has been solved.

You can refer to here for more details.

在此处输入图像描述

在此处输入图像描述

Your code is trying to run using MINGW which is not for python. You can simply use Code Runner to run your python code

I also had this problem. And I solved this.

  • Don't use terminal.integrated.defaultProfile.windows .
  • Use this terminal.integrated.shell.windows as default.

This is my config.

"terminal.integrated.profiles.windows": {
            "PowerShell": {
                "source": "PowerShell",
                "icon": "terminal-powershell"
            },
            "Command Prompt": {
                "path": [
                    "${env:windir}\\Sysnative\\cmd.exe",
                    "${env:windir}\\System32\\cmd.exe"
                ],
                "args": [],
                "icon": "terminal-cmd"
            },
            "Git Bash": {
                "source": "Git Bash",
                "icon": "terminal-bash"
            }
        },
"terminal.integrated.shell.windows": "D:\\Scoop\\apps\\git\\current\\bin\\bash.exe",

And then restart VSCode. I hope this will help you.

Or you can use the command of the terminal to compile and run the target program, hoping to help you ~

Try to:

  • restart vscode or your system or
  • reselect the terminal using dropdown menu on the right side of your terminal. It should help and remove '&' from the beginning of the command prompt.

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