Skip to content

Shell type is detected incorrectly after VSCode update #16175

Closed

Description

@mattkellymt

Error: & was unexpected at this time

Workaround: #16175 (comment)

When I run a python script, without ever changing a setting in vs code after its installation, it uses powershell as the default terminal profile and there is no issue.

image

But when I change the default terminal profile from powershell to command prompt

image
image

I get the "& was unexpected at this time." error

image

I've seen people say I should type ctrl+shift+p then type "select default terminal" to change my terminal from powershell to the command prompt, but this isn't an option in the 2021-05-06 version of Visual Studio Code

image
image

I am using a fresh Windows 10 install with nothing but miniconda and visual studio code.

Activity

  1. added
    triage-neededNeeds assignment to the proper sub-team
    bugIssue identified by VS Code Team member as probable bug
    on May 7, 2021
  2. Sunillad08 commented on May 7, 2021

    @Sunillad08

    I tried changing default terminal to cmd but it still runs .ps1 instead of .bat file for venv . We can manually run .bat file and it will work in cmd.

  3. mattkellymt commented on May 7, 2021

    @mattkellymt
    Author

    I tried changing default terminal to cmd but it still runs .ps1 instead of .bat file for venv . We can manually run .bat file and it will work in cmd.

    When you Sunil Lad (@Sunillad08) say "we can manually run .bat" are you suggesting that I do this?

  4. Sunillad08 commented on May 7, 2021

    @Sunillad08

    I tried changing default terminal to cmd but it still runs .ps1 instead of .bat file for venv . We can manually run .bat file and it will work in cmd.

    When you Sunil Lad (@Sunillad08) say "we can manually run .bat" are you suggesting that I do this?

    Not really , you can run that if you want to work with cmd only . I was just addressing that I got same issue.

  5. banggua commented on May 7, 2021

    @banggua

    terminal.integrated.shell.windows works good for me, but terminal.integrated.defaultProfile.windows doesn't.

  6. skilkis commented on May 8, 2021

    @skilkis

    Can confirm that this is also the case when using Git Bash as terminal.integrated.shell.windows works while terminal.integrated.defaultProfile.windows does not. According to Brett Cannon (@brettcannon)'s answer, Git Bash is not officially supported but I had no issues prior to the introduction of the new terminal settings with VS Code 1.56. To clarify here are my settings:

        "terminal.integrated.defaultProfile.windows": "Git Bash",
        "terminal.integrated.profiles.windows": {
            "Git Bash": {
                "source": "Git Bash",
                "icon": "terminal-bash"
            }
        },
        "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",

    Which results in the correct activation command:

    $ source c:/Users/MDRyzenPC/Python/numfoil/.venv/Scripts/activate
    (.venv) 

    Wheras with the terminal.integrated.shell.windows setting omitted the output is:

    $ & c:/Users/MDRyzenPC/Python/numfoil/.venv/Scripts/Activate.ps1
    bash: syntax error near unexpected token `&'

    Therefore, it seems like vscode-python is not using the new settings yet!

  7. banggua commented on May 8, 2021

    @banggua

    I disable it by setting "python.terminal.activateEnvironment": false,. I control the activation of the Python environment through .bashrc. I always use python -m venv venv to create a new Python environment in my project, so I add [ -f "venv/Scripts/activate" ] && source venv/Scripts/activate to .bashrc. The important thing is that it works well for me.

    vscode settings.json

    "python.terminal.activateEnvironment": false,
    "terminal.integrated.defaultProfile.windows": "Git Bash",
    "terminal.integrated.profiles.windows": {
        "Git Bash": {
            "source": "Git Bash"
        }
    },

    .bashrc

    function pyenv() {
        python -m venv venv
        pyac
        python -m pip install -U pip setuptools
    }
    function pyac() {
        [ -f "venv/Scripts/activate" ] && source venv/Scripts/activate
    }
    function pyde() {
        deactivate
    }
    function pylock() {
        pip freeze >requirements.txt
    }
    function pyinstall() {
        pip install -r requirements.txt
    }
    pyac
  8. asdasd-123 commented on May 10, 2021

    @asdasd-123

    Also having this issue since the latest update. Worked fine before the weekend then from launch today I've been getting the issue.

    I used the workaround San Kilkis (@skilkis) showed and that seems to have resolved it for now so would recomend that if anyone else is have trouble

  9. karrtikr commented on May 10, 2021

    @karrtikr

    Thanks for the bug report! We just wanted to quickly acknowledge we received it and we will triage this as soon as we can. #16169 could be related.

  10. 7 remaining items

  11. removed their assignment
    on May 11, 2021
  12. changed the title [-]& was unexpected at this time.[/-] [+]Shell type is detected incorrectly after VSCode update[/+] on May 11, 2021
  13. karrtikr commented on May 12, 2021

    @karrtikr

    Please try the workaround mentioned here: #16175 (comment)

  14. ChandlerTayek commented on May 12, 2021

    @ChandlerTayek

    Please try the workaround mentioned here: #16175 (comment)

    Confirming that this workaround worked for git bash.
    Steps I took:

    1. Set my default profile to Git Bash.
    2. Then I added "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe" in my .../user/settings.json file.

    Worked like a charm thank you Kartik Raj (@karrtikr) and banggua

  15. karrtikr commented on May 12, 2021

    @karrtikr

    Blocked on getting upstream vscode issue fixed microsoft/vscode#121760

  16. Tyriar commented on May 12, 2021

    @Tyriar

    We're switching the default priority to always use the shell setting over the default profile if specified microsoft/vscode#123174. Unfortunately there isn't an easy/low risk fix for this other than that workaround.

  17. karrtikr commented on May 12, 2021

    @karrtikr

    I have followed up in the original issue. microsoft/vscode#121760 (comment)

  18. karrtikr commented on May 14, 2021

    @karrtikr

    Hi everyone 👋 The fix seems to be now available on VSCode insiders. Please try it out and let us know how it goes.

    FYI things are better but I'm still having this issue microsoft/vscode#121760 (comment), you may also see it.

  19. ChandlerTayek commented on May 14, 2021

    @ChandlerTayek

    Kartik Raj (@karrtikr) I'm able to select different default profiles and have the correct behavior with the insiders build.

  20. karrtikr commented on May 21, 2021

    @karrtikr

    Should be fixed in the next stable release of VSCode. Note if you have both settings we prioritize the shell setting for now, #16175 (comment).

  21. locked as resolved and limited conversation to collaborators on Sep 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-terminalbugIssue identified by VS Code Team member as probable bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions