Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save guimondmm/1a2e47d73a191429c7f8b0c12729dc59 to your computer and use it in GitHub Desktop.
Save guimondmm/1a2e47d73a191429c7f8b0c12729dc59 to your computer and use it in GitHub Desktop.
Add an "Anaconda PowerShell Prompt" profile to Windows Terminal. Just paste it in your settings.json file.
{
"colorScheme": "Campbell",
"commandline": "pwsh.exe -ExecutionPolicy ByPass -NoExit -Command \"& '%USERPROFILE%\\anaconda3\\shell\\condabin\\conda-hook.ps1' ; conda activate '%USERPROFILE%\\anaconda3' \"",
"guid": "{e7d34d61-5a57-4f38-8eab-91cb777b0c26}",
"hidden": false,
"icon": "%USERPROFILE%\\anaconda3\\Menu\\anaconda-navigator.ico",
"name": "Anaconda PowerShell Prompt",
"startingDirectory": "%USERPROFILE%"
}
@guimondmm
Copy link
Author

Description

This Windows Terminal profile launches PowerShell with exactly the same command as Anaconda Navigator does, except it uses the new and improved pwsh.exe (PowerShell Core), instead of the old powershell.exe (Windows PowerShell 5.1), which still ships with Windows as of writing these lines.

That is to say, this profile sources Anaconda's conda-hook.ps1 script, which automatically sets the required environment variables, and activates the base Conda environment. This means you don't need to add Conda to PATH to use your Conda environment in Windows Terminal. It's also more convenient and much faster to launch PowerShell this way than to let conda init wreak havoc on your PowerShell profile.

Just paste this profile at the appropriate location inside your settings.json file, which can be accessed by click the cog in the lower left corner of the Windows Terminal Settings pane.

Caveats

  • As it stands, this profile uses the first pwsh.exe in PATH. If you'd prefer to hardcode the path instead, you can use the (Get-Command 'pwsh.exe').Path cmdlet to get the full path to pwsh.exe.
  • Similarly, this profile assumes your Anaconda install is located at %USERPROFILE%\anaconda3, which is the default folder. Change the path if need be.
  • You don't need to edit your environment variables, and you don't need to add Anaconda to PATH. And you definitely shouldn't let conda init make changes to your Microsoft.Powershell_profile.ps1 file.
  • Don't forget to separate profiles with a comma in your settings.json file. Also, don't forget to escape double quotes and backslashes if you edit the paths to PowerShell or Anaconda.
  • In the extraordinarily unlikely event the GUID above collides with another one of your Windows Terminal profiles, or you don't like the cut of its jib or something, you can generate a new random GUID using the New-Guid cmdlet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment