Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run powershell.exe with Anaconda in new windows terminal profiles?

New Windows Terminal (Windows Terminal (Preview) Version: 0.2.1831.0) have settings in JSON file. How can I setup powershell running with Anaconda? Anaconda running in powershell with:

%windir%\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy ByPass -NoExit -Command "& 'C:\Users\akali\Anaconda3\shell\condabin\conda-hook.ps1' ; conda activate 'C:\Users\akali\Anaconda3' "

Windows Terminal use profiles in JSON like this:

  "profiles": [{
       "colorScheme": "Solarized Light",
       "commandline": "powershell.exe"
   }]

How can I use running with Args with double quote in JSON that allow me run something like -Command "& 'C:\'"?

like image 918
Denis Savenko Avatar asked Dec 07 '22 11:12

Denis Savenko


1 Answers

I realize I'm late of some years but I had a similar problem and stranded up here looking for an answer. So, I'm hoping that this is useful for people like me in the future.

After some time tinkering I generated an Anaconda profile:

  • copy paste an existing profile
  • generate guid here
  • open C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Anaconda3 (64-bit)
  • right click on Anaconda Powershell Prompt (Miniconda3) and go to Properties
  • copy the entire content of the target field and paste it on the field commandline (make sure the field is commandline and not source)
  • escape all the \ characters (\ --> \\)
  • Change the name field

You should have something like this

{
        "guid": "{generated guid}",
        "hidden": false,
        "name": "Anaconda",
        "commandline": "powershell.exe -ExecutionPolicy ByPass -NoExit -Command & 'C:\\ProgramData\\Miniconda3\\shell\\condabin\\conda-hook.ps1' ; conda activate 'C:\\ProgramData\\Miniconda3'"
        
    },

As a nice sidenote, you can also create a profile to directly launch an Ipython session or a jupyter notebook. As you may have noticed, lo launch anaconda in the commandline field we are just launching powershell.exe, and then telling the powershell instance to execute a -Command, which is the subsequent string. Were you to add a ; ipython to the command, you would launch an ipython session.

like image 152
Marco Necci Avatar answered May 12 '23 09:05

Marco Necci