Ever wanted to open an Anaconda Prompt by right clicking the folder in Explorer in Windows 10? Git Bash has an entry in the right-click context menu and so does Powershell (just Shift + Right-Click). Anaconda doesn't have one by default and I wanted to add it. But none of the answers on Stack Overflow or a bunch of other sites worked. I finally got it working after reading the Wikipedia entry for cmd.exe
.
Here is the batch file:
REM Run this as administator. REM Check the path to the activate script depending where you installed Anaconda / version. REG ADD HKCR\Directory\Background\shell\Anaconda\ /ve /f /d "Anaconda Prompt Here" REG ADD HKCR\Directory\Background\shell\Anaconda\command /f /ve /t REG_EXPAND_SZ /d "cmd.exe /k pushd %%v && %%USERPROFILE%%\Anaconda3\Scripts\activate.bat" REG ADD HKCR\Directory\shell\Anaconda\ /ve /f /d "Anaconda Prompt Here" REG ADD HKCR\Directory\shell\Anaconda\command /f /ve /t REG_EXPAND_SZ /d "cmd.exe /k pushd %%v && %%USERPROFILE%%\Anaconda3\Scripts\activate.bat"
Save it as “anaconda.bat” and run it as Administrator and it will install the correct registry keys. After running this script, the prompt will be in your right-click context menu for each folder in Explorer.
I'll attempt to explain how this works:
Directory\Background\shell
and Directory\shell
. I believe the Background entry is for right-clicking on the background / empty part of the folder in Explorer (right pane) and the plain Shell entry is for right-clicking the folder itself (in either the left or right panes).cmd.exe /k [command]
runs the command specified. In this case, it is pushd %%v && %%USERPROFILE%%\Anaconda3\Scripts\activate.bat
which is two commands put together.pushd %%v
switches the prompt to the folder being clicked. There are two %
because it is an escaped character in the batch file.&&
strings two commands to be executed in sequence%%USERPROFILE%%\Anaconda3\Scripts\activate.bat
is the command to activate the Anaconda environment, if you installed it in your user folder. It will be stored in the registry as %USERPROFILE%\Anaconda3\Scripts\activate.bat
, which means each user will use their own copy of activate.bat in their own folder.
Discussion