How to fix Code not displaying anaconda prompt as Terminal? - visual-studio-code

The Python interpreter is working fine and is fully configured. So it should be using the anaconda prompt by default for the Terminal. However this has not been the case so I tried setting up manually. This is what I've set so far:
This is the prompt when I hover over 'terminal.inegrated.defaultProfile.windowss" value:
Also 'Anaconda Shell' is not selectable from the dropdown for the Terminal sub-window. It doesn't show there but the rest are being displayed:
Is there a away to actually override Code to recognise the anaconda prompt to be set as default?

You need to configure it like this:
"Anaconda": {
"path": "cmd.exe",
"args": ["/K", "C:\\ProgramData\\Anaconda3\\Scripts\\activate.bat"]
}

Related

VS Code- "Run" button not appearing for my Jupyter Notebook, even after installing extensions and setting kernel

TL;DR: how can I run my Jupyter notbook in VS Code, given I've tried the previously-suggested solutions (like installing certain extensions) and nothing appears to be working?
I've got the following blank .ipynb file:
I've installed both Microsoft's Jupyter and Python extensions installed:
I created the file in screenshot #1 above via the command palette to Jupyter > Create New Blank Notebook. We see a cell which I've changed from plain text to Python. I don't see a "Run" button in my editor like I do in the VS Code + Jupyter docs. I hit Shift-Enter to run the cell, but instead of the expected output, I'm prompted to "Select a kernel for Untitled-1.ipynb`:
I try to type in my best guess for which kernel they're referring to (I use Python 3.9.5 in my terminal), but typing things like 3.9.5 and Python, thinking I might see an auto-complete helper or a dropdown with valid options to choose from, but this didn't happen.
The "Restart" and "Interrupt" buttons are greyed-out and disabled, implying that the Jupyter server isn't running. However, the docs imply that I should be able to just create a new Jupyter notebook and start running code immediately:
Here’s how to get started with Jupyter in VS Code.
If you don’t already have an existing Jupyter Notebook file, open the
VS Code Command Palette with the shortcut CTRL + SHIFT + P (Windows)
or Command + SHIFT + P (macOS), and run the “Python: Create Blank New
Jupyter Notebook” command.
If you already have a Jupyter Notebook
file, it’s as simple as just opening that file in VS Code. It will
automatically open with the new native Jupyter editor.
Once you have a Jupyter Notebook open, you can add new cells, write code in cells, run cells, and perform other notebook actions.
I saw the following Jupyter Server: local component at the bottom of my screen. I see the icon on the left-hand side shows a disconnected power cord; not sure if that implies the server itself is disconnected. At any rate, I tried clicking on this component to see what would happen:
I see the default behavior is already selected, which leads me to believe that VS Code would automatically start up a Jupyter server when the app itself is launched.
I also tried setting the kernel via the command palette (Jupyter > Select interpreter to start Jupyter server), and this time I did see my version of Python. However, selecting that option didn't seem to resolve the issue, since I still don't see a "Run" button:
I tried looking in all the tabs at the bottom of the screen (Terminal, Jupyter Variables, Debug Console, Problems, and Output), but didn't see anything at all.
Interestingly, when I run Jupyter > Create Interactive Window from the command palette, I am able to create Jupyter cells and run Python code in them. However, I consider this to be a workaround and not a solution to my primary problem of being unable to run both interactive sessions and notebooks:
These are all my VS Code settings:
{
"ruby.intellisense": "rubyLocate",
"files.autoSave": "onFocusChange",
"workbench.editor.showTabs": true,
"diffEditor.ignoreTrimWhitespace": false,
"files.trimTrailingWhitespace": true,
"editor.tabSize": 2,
"editor.tabCompletion": "on",
"workbench.colorCustomizations": {
"editorUnnecessaryCode.border": "#dd7aab"
},
"window.zoomLevel": 1,
"terminal.integrated.shell.osx": "/bin/zsh",
"[yaml]": {
"breadcrumbs.showEvents": true,
"editor.insertSpaces": true,
"editor.tabSize": 2,
"editor.autoIndent": "advanced"
},
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"workbench.editor.untitled.hint": "hidden",
"workbench.editorAssociations": {
"*.ipynb": "jupyter-notebook"
},
"notebook.cellToolbarLocation": {
"default": "right",
"jupyter-notebook": "left"
},
"python.defaultInterpreterPath": "/usr/local/bin/python3",
"notebook.lineNumbers": "on",
"jupyter.variableQueries": [
],
}
What am I missing?
Here is your answer,
1.Just refresh your IDE and then restart your IDE .
2.INSTALL KERNEL ON YOUR IDE.
Sometimes extensions in IDE must not have hosted therefore the extensions does not work.In this case just restart your IDE and then host your extensions.
I am not sure if you're still searching for an answer.
What worked for me was to install conda (anaconda or miniconda will do).
Then in the command prompt, type:
conda install ipykernel
Restart your IDE and it should work!
I had this issue too and solved it by:
pip install ipython
After installing this package and Jupyter extensions in Visual Studio code, the run button is available left of the cell and you can click it to run the cell.
Then it tries to connect to the kernel and for the first time asks you to install Ipykernel if it doesn't show this message, etc you can run this code in Command Prompt:
python -m pip install ipykernel
also for more information, you can see this page:
https://ipython.readthedocs.io/en/latest/install/index.html
Go to Extension
Search "Jupyter" from Microsoft
Click "Switch to Pre-Release Version"
Click "Reload"
VS Code Extension

How do I get around the verified bug in Windows 1903 and launch the VSCode integrated terminal?

I just did a fresh install of Windows 10 Pro version 1903 build 18362.116 and Visual Studio Code. Now the integrated terminal only launches externally.
Pressing Ctrl + ~ results in this.
What am I missing? How do I get it to open integrated again?
EDIT
After working with VSCode team it is a verified bug. See the Github issue here. I posted the workaround as an answer here.
OK, worked through this one in VSCode repo issues.
For now, until it's fixed, turn off ConPTY integration in the User Settings.
💥💥💥
The issue now says use legacy console. To change the setting open a cmd prompt. Right click the title to bring up properties.
Then Uncheck 'Use legacy console'
To change the integrated terminal on Windows, you just need to change the terminal.integrated.shell.windows line:
Open VS User Settings (Preferences > User Settings). This will open two side-by-side documents.
Check if "terminal.integrated.shell.windows" has value "C:\\Bin\\Cmder\\Cmder.exe" setting to the User Settings document on the right.
Remove this line.
Ctrl + ~ will now open integrated terminal of VSCode.
If the above solution doesn't work then can you try below values and check if it works for you:
// Command Prompt
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe"
// PowerShell
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
// Git Bash
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe"
// Bash on Ubuntu (on Windows)
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\bash.exe"
From the Command Palette (Ctrl+Shift+P), use the View: Toggle Integrated Terminal command.
Try custom shortcut:
[
{
"key": "ctrl+`",
"command": "workbench.action.terminal.toggleTerminal"
}
]
Had this problem fixed. Found the solution from the VS Code support.
for error:
Terminal exits with code 3221225786 (or similar)#
"This can happen when you have legacy console mode enabled in conhost's properties. To change this, open cmd.exe from the start menu, right-click the title bar, go to Properties and under the Options tab, uncheck Use legacy console."
source: VS Code docs

VSCode default Integrated Terminal is not changing

I'm using VSCode for some time now and until today the Terminal was working as expected.
But now I can't change the default Integrated Terminal. It's allways "cmd" no matter what I set up in the settings.
The settings.json seems to be fine:
{
"window.zoomLevel": -1,
"files.associations": {
"*.testset": "feature"
},
"git.autofetch": true,
"C_Cpp.updateChannel": "Insiders",
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe"
}
But every new terminal is still "cmd".
Not "bash" or "PS".
The issue was in my workspace settings.
"project.code-workspace"
{
....
"settings": {
"terminal.integrated.shell.windows": "cmd.exe"
}
}
By removing this line from the file, the problem was fixed. Now I can change the default Integrated Terminal.
most of the time this issue happens when new updates come,
the easiest ways to solve this is:
https://youtu.be/jpwfr6m50sI - here you will see how to change the default terminal
uninstall your vscode install the previous one (if you don't know how to do this, follow this: How to downgrade vscode )
Dont hesitate to report to GitHub of vscode team as well as follow
their documentaries

Integrated terminal setup for msys mingw not working for build task

I have managed to get the integrated terminal working with msys (bash) terminal using the following settings:
"terminal.integrated.shell.windows": "C:\\msys64\\bin\\msys_shell.cmd",
"terminal.integrated.shellargs.windows": "-mingw64 -defterm -nostart",
"terminal.integrated.env.windows": "HOME": "${workspace Folder}"
And this works well. I had to add the env "HOME" entry to get the sh to start in the correct home directory as it wouldn't work with (or with nothing at all):
"terminal.integrated.cwd": "${workspaceFolder}"
Now I have run into another problem. While the above settings work perfectly for a terminal window they fail for the build task. So I am forced to manually "make" from the integrated terminal window.
It fails with with error:
/d: /d: is a directory
My environment is Windows 10 msys64 mingw64.
Any ideas appreciated!
I ran into the same issue today. On their help page for tasks.json they talk about the options fields in the settings.
VSCode uses the default shell for tasks unless you tell it not to. Additionally you'll have to pass your command to the resulting shell. I solved that using -shell bash -c so bash runs the command immediately.
The syntax is something like this:
"command": "make -j8",
"options": {
"shell": {
"executable": "C:\\msys2\\msys2_shell.cmd",
"args": ["-defterm", "-mingw64", "-no-start", "-here", "-shell bash -c"]
}
}

How to add multiple terminals in VS Code?

Can we add multiple different terminals in the VS Code? I am planning to add following three terminal and work with all of those :
Windows Command prompt
PowerShell
Git Bash
I know I need to add the following command in Preferences => Setting
// // 64-bit cmd if available, otherwise 32-bit
"terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\cmd.exe",
// // 64-bit PowerShell if available, otherwise 32-bit
"terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe",
// // Git Bash
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",
I want to add all of the above three commands in setting.json
And when I click + different terminal should open and I want to work with those terminals without changing the preferences.
Is it possible in VS Code or not?
There is a way to make this happens with these steps by installing an extension:
Find an extension called Shell launcher and install it or you can find it here. Reload VS Code if you want or after you finished all steps.
Go to Files --> Preferences --> Settings and this will open settings.json file and you then insert this (you can edit this to your heart's content):
Code:
"shellLauncher.shells.windows": [
{
"shell": "C:\\Windows\\<sysnative>\\cmd.exe",
"label": "cmd"
},
{
"shell": "C:\\Windows\\<sysnative>\\WindowsPowerShell\\v1.0\\powershell.exe",
"label": "PowerShell"
},
{
"shell": "C:\\Program Files\\Git\\bin\\bash.exe",
"label": "Git bash"
},
{
"shell": "C:\\Windows\\<sysnative>\\bash.exe",
"label": "WSL Bash"
}
]
PS: You can use shellLauncher.shells.linux for Linux or shellLauncher.shells.osx for macOS.
Go to Files --> Preferences --> Keyboard Shortcuts and then find on {} icon on the top right corner to open keybindings.json file. Insert this:
Code:
[
{ "key": "ctrl+alt+`", "command": "shellLauncher.launch" }
]
Update: Type shelllauncher into the search bar. You can then see Shell Launcher: Launch command. Highlight and use any keybinding you like. For example, I picked Ctrl + Alt + (backtick)` for myself.
You can reload your VS Code and click the key combination you have assigned and that will give you the option to choose which integrated terminal you want to use.
For more details, please check the official site: https://marketplace.visualstudio.com/items?itemName=Tyriar.shell-launcher
Enjoy!
Even the question is asked last year and the answer is accepted but still I feel to answer this question as I didn't found any simple, suitable and complete answer while as a development I need multiple terminal handy in a click like below:-
and I don't bother about their path, add another extension for what the VS Code is already capable of or reload VS Shell etc and go to insert and setup the settings files manually.
I found this question is asked many times and almost all landed up manually setup of write some settings etc. or sometimes only opted to get a single type of terminal. The answer of #Pawan is somewhat near but again that solution finally land up to a single terminal, going to command setup for switch terminal and this one will work for git or any other terminal.
If you have tools installed which worked on command line like power-shell and git along with default cmd prompt in windows then the follow the quick three steps to get all terminals at once and switch to anyone with a click.
Open terminal, it should be visible (use ctrl+` or from menu View-> Integrated Terminal )
Open commands search (use Ctrl+Shift+P or from menu View->Command Palette...)
In command box Type "Terminal: Select Default Shell" to select this option from drop down.
As you select this option, then all the available commands which are in path will be listed below like below
Just click any one which you like to add for quick access from command list.
Finally, in the terminal window, just click on + sign next to terminal list as shown below:-
The terminal selected in step 5 will now added after performing step6 to the list without removal of earlier terminal.
Repeat step 3-6 for adding any other terminal to command list.
To work with particular terminal just select the required one in the terminal list of the terminal window.
press ctrl + shift + ` shortcut, or press a cross sign to run new terminal, then type bash if your default mode is powershell or powershell if your default mode is bash. And here you are, your terminal is switched.
For now VS Code support defining only one of available terminals as default at a time and you can not add multiple shell terminals.
If you don't want to install "Shell Launcher" plugin as suggested by #ian0411 then here is a quick way to change/select default terminal.
Press "Ctrl + Shift + P" to open the Command Palette.
Type "Terminal: Select Default Shell" and hit enter. You will be prompted to select Git Bash, PowerShell or Cmd as shown below:
Note: This will change the default shell terminal but there is no harm changing it whenever you need to use another.
BTW, if you need to switch only between Cmd & Powershell then you can type cmd or powershell (in already opened terminal) to switch to desired terminal. But it would not work for Git Bash.
I don't see this in the above, but read all the answers. I think this is the best approach for what is supported right now. I believe, like myself, the OP simply wants to open VSCode, and down yonder on the terminal window, we just want a list of options to open from.
Yes, you can open the command, "Terminal: Select Default Shell" and loop through that to add various types of terminals...
Followed by:
I don't know when this option was added to the dropdown, but look! No need to start by looking up the command. I think this is a lot smoother than any other answer, but it still results in the annoying overwrite of your default term to whatever your last choice was before leaving session.
Here, we can more easily open the Select Default Shell - it should support "Select New Shell". Simple, you'd think. Hopefully someone adds that soon or I have time to contribute.
I'm fairly certain that these are old-style settings.json and won't work as discussed in VS Code 2021. The new style looks like:
...
"terminal.integrated.profiles.windows":
{ "Bash":
{ "path": ["C:\\Programs\\Git\\bin\\bash.exe"],
"icon": "terminal-bash",
},
"Command Prompt":
{ "path": ["${env:windir}\\System32\\cmd.exe"],
"args": [],
"icon": "terminal-cmd"
},
"PowerShell":
{ "path": ["C:\\Programs\\PowerShell\\pwsh.exe"],
"source": "PowerShell",
"args": [],
"icon": "terminal-powershell"
},
},
"terminal.integrated.defaultProfile.windows": "Bash"
...
That will get you access to Command and PowerShells and set bash as the default shell (my preference). If you want to launch a standalone application like git-bash, you will need something else.
As of https://code.visualstudio.com/updates/v1_35 you can now:
select from the pulldown menu directly above the terminal "Select Default Shell"
select the one you like
click the +
done
(the same goes for opening split screen: before this do 1 + 2 and then click the split screen button)
(although overriding the default but does no longer matter if this is your flow)
This can be done by adding a different key at the end. By just changing your example to:
// // 64-bit cmd if available, otherwise 32-bit
"terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\cmd.exe",
// // 64-bit PowerShell if available, otherwise 32-bit
"terminal.integrated.shell.windows2": "C:\\Windows\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe",
// // Git Bash
"terminal.integrated.shell.windows3": "C:\\Program Files\\Git\\bin\\bash.exe",
Note that the key ...shell.windows is changed to ...shell.windows2 and ...shell.windows3.
Follow-up finding: I've noticed that once restart of the IDE, only the first terminal gets displayed. I had to reopen the settings and save it once to get both the terminals again. Will post if any better solution available.
In the terminal tab, there's a Split Terminal button. Works like a charm
To open the multiple terminal please check the screen shot for the same(on the right bottom of the visual studio code their will be a dropdown and just after it, their is +(plus) icon . On pressing it the new terminal will open.).
The recommended way to automatically open multiple terminal windows is to use the Tasks feature. See Automating launching of terminals in the VS Code documentation.
For WSL Ubuntu on Windows terminal:
File -> preferences -> settings -> click code icon in top right
Enter the following:
{
"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\wsl.exe",
"git.enableSmartCommit": true
}