1

As the title suggests, I would like to run Anaconda's ipython on Windows 10's Windows Terminal (Preview) (preferrably in the cmd.exe tab) in one go.

By in one go I mean, with a single shortcut or batch file, I can start to work with ipython environment in Windows 10's Windows Terminal (perview).

Currently I can do it in 3 steps:

  1. Open Windows Terminal (Preview). Alternatively, I can create a shortcut to the program, whose path is C:\Program Files\WindowsApps\Microsoft.WindowsTerminal_0.5.2661.0_x64__8wekyb3d8bbwe\WindowsTerminal.exe. I have changed the preference so that the default tab is cmd.exe instead of PowerShell.

  2. Within Windows Terminal (Preview), start Anaconda's environment by entering C:\Anaconda3\Scripts\activate.bat C:\Anaconda3, where C:\Anaconda3 is my installation folder. Then each line of the prompt will start with (base).

  3. Enter ipython in the prompt. Ipython will then start. The prompt now becomes like In [1]:.

But I do not know how to combine the above 3 steps into one, with a batch file or anything. Any idea that helps the automation is much appreciated!

Edit: For your reference, the content of C:\Anaconda3\Scripts\activate.bat is

@REM Copyright (C) 2012 Anaconda, Inc
@REM SPDX-License-Identifier: BSD-3-Clause
@REM Test first character and last character of %1 to see if first character is a "
@REM   but the last character isn't.
@REM This was a bug as described in https://github.com/ContinuumIO/menuinst/issues/60
@REM When Anaconda Prompt has the form
@REM   %windir%\system32\cmd.exe "/K" "C:\Users\builder\Miniconda3\Scripts\activate.bat" "C:\Users\builder\Miniconda3"
@REM Rather than the correct
@REM    %windir%\system32\cmd.exe /K ""C:\Users\builder\Miniconda3\Scripts\activate.bat" "C:\Users\builder\Miniconda3""
@REM this solution taken from https://stackoverflow.com/a/31359867
@set "_args1=%1"
@set _args1_first=%_args1:~0,1%
@set _args1_last=%_args1:~-1%
@set _args1_first=%_args1_first:"=+%
@set _args1_last=%_args1_last:"=+%
@set _args1=

@if "%_args1_first%"=="+" if NOT "%_args1_last%"=="+" (
    @CALL "%~dp0..\condabin\conda.bat" activate
    @GOTO :End
)

@REM This may work if there are spaces in anything in %*
@CALL "%~dp0..\condabin\conda.bat" activate %*

:End
@set _args1_first=
@set _args1_last=
1
  • Thanks for asking! I list the content in the edit to the question.
    – aafulei
    Oct 2, 2019 at 13:48

1 Answer 1

4

Procedure:

  • Open Windows Terminal. Press Ctrl + , to open settings.json file in default text editor.

  • Add this following JSON object to the profile array.

{
    "guid": "{ee4fe116-1375-4c00-925c-1e361f99496d}",
    "name": "Anaconda ipython",
    "commandline": "cmd.exe /C C:\\Anaconda3\\Scripts\\activate.bat C:\\Anaconda3 & ipython",
    "hidden": false
},
  • Change the defaultProfile value to that GUID to automatically open Anaconda ipython on startup.
"defaultProfile": "{ee4fe116-1375-4c00-925c-1e361f99496d}",

Explanation:

What does the commandline do? It executes cmd.exe with the activate.bat file. The /C option carries out the command in cmd.exe then terminates. If you want to prevent termination use /K option. The Ampersand symbol (&) is to execute ipython command after executing the activate.bat file.

The GUID is randomly generated using uuidgen, check if it does not match with other profiles GUID in that JSON file. See this answer for more details on how to edit JSON file.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .