Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix "Shell Integration failed to activate" error in VS Code?

It used to work fine, but recently whenever I run my code (Python), I get the message

Shell Integration failed to activate

when I hover my mouse over the active terminal. The active Python terminal doesn't recognize any command line commands like "pip" anymore (see screenshot):

screenshot

What can I do? I played around with a couple of settings as described here, but nothing seems to work. My current setting.json file looks like this:

{    
    "python.defaultInterpreterPath": "C:\\Users\\cleme\\AppData\\Local\\Programs\\Python\\Python310\\python.exe",
    "terminal.integrated.profiles.windows": {
        "PowerShell": {
            "path": "C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe",
            "source": "PowerShell",
            "icon": "terminal-powershell",
        }
    },
    "terminal.integrated.defaultProfile.windows": "PowerShell"
}
like image 764
lapislazuli Avatar asked Aug 07 '26 06:08

lapislazuli


2 Answers

I ended up deleting the whole Code folder within the C:\Users\AppData\Roaming.

Note: You have to check the box - view Hidden Files to see these folders within File Explorer.

This solved it.

There must have been some weird corrupted cache issue at the heart of this.

I found this in C:\Users<profile>\AppData\Roaming\Code\logs<datetimestamp>\ptyhost.log

[2022-10-17 07:25:50.695] [ptyhost] [warning] Couldn't get layout info, a terminal was probably disconnected Could not find pty on pty host
[2022-10-17 07:25:54.040] [ptyhost] [warning] Shell integration cannot be enabled for executable "C:\Windows\System32\cmd.exe" and args []
[2022-10-17 07:26:57.939] [ptyhost] [warning] Shell integration cannot be enabled for executable "C:\Windows\System32\cmd.exe" and args []

I think it is related to this.

BTW: I had tried adding a couple of PowerShell VSCode IDE Extensions when things went awry. IIRC they were:

  • PowerShell
  • PowerShell Preview

I had upgraded PowerShell to the latest version 7 too.

$PSVersionTable yielded the following from the respective executables.

Executable Path Version
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe 5.1.17763.1852
C:\Program Files\PowerShell\7\pwsh.exe 7.2.6

Maybe that combo hosed things

Follow up note: Whilst it seemed to have fixed the issue once... soon after the problem manifested itself again. This time I couldn't reset VS Code to a working environment.

  • Then I realised had opened the Project folder in the explorer on the left of the IDE.
  • I had a subfolder that had a PS1 file within that.
  • It didn't have its own .vscode\settings.json
  • When I copied it down from the parent folder, suddenly everything worked again.

.vscode\settings.json just contained this:

{
}

Again this ended up being a one time solution. I ended up back at:

Shell activation failed to activate for cmd.exe

I posted this as a new ticket here

  • In the end I found this to be more of a display issue than anything else!
  • You can actually type cls then hit ENTER, to restore things to the status quo.
  • The Terminal section is black with no prompt to begin with. But you can type in it!!!
  • Perhaps the Prompt is black text on a black background initally, since when you start typing cls, it's quite a way to the right of the left margin.
like image 199
JGFMK Avatar answered Aug 10 '26 13:08

JGFMK


Closing VSCode, verifying that powershell works, then reopening it worked for me.

like image 23
arasu ramanan Avatar answered Aug 10 '26 14:08

arasu ramanan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!