flawr
flawr

Reputation: 11638

Execute certain commands when opening Anaconda Prompt?

When using Anaconda in Windows you get a shortcut to the "Anaconda Prompt" which is a cmd window that with the base-environment activated and probably all the conda commands loaded. Is there a way to have some commands executed when starting it?

I'd like to have it change to a specific directory and activate a specific environment other than base.

Upvotes: 5

Views: 4034

Answers (1)

flawr
flawr

Reputation: 11638

The "Anaconda Prompt" is actually a link executing

%windir%\System32\cmd.exe "/K" C:\ProgramData\Anaconda3\Scripts\activate.bat C:\ProgramData\Anaconda3

The flag /k provided to cmd executes the subsequent commands, in this case activate.bat. To execute more commands we can just add them using the command separator &&, so we can use

%windir%\System32\cmd.exe "/K" C:\ProgramData\Anaconda3\Scripts\activate.bat 
C:\ProgramData\Anaconda3 && cd some_directory && conda activate some_environment

Upvotes: 5

Related Questions