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
many thanks for your post. Check out the following script which word for me. It even adds the menu for library folders. Also check %%1 instead of %%v to start with the correct folder!
Greetings, Mark from Germany
REG ADD HKCR\Directory\Background\shell\Anaconda\ /ve /f /d "Open in Anaconda"
REG ADD HKCR\Directory\Background\shell\Anaconda\ /v Icon /f /t REG_EXPAND_SZ /d %%USERPROFILE%%\\miniconda3\\Menu\\Iconleak-Atrous-Console.ico
REG ADD HKCR\Directory\Background\shell\Anaconda\command /f /ve /t REG_EXPAND_SZ /d "%windir%\System32\cmd.exe /K pushd %%v && %%USERPROFILE%%\miniconda3\Scripts\activate.bat"
REG ADD HKCR\Directory\shell\Anaconda\ /ve /f /d "Open in Anaconda"
REG ADD HKCR\Directory\shell\Anaconda\ /v Icon /f /t REG_EXPAND_SZ /d %%USERPROFILE%%\\miniconda3\\Menu\\Iconleak-Atrous-Console.ico
REG ADD HKCR\Directory\shell\Anaconda\command /f /ve /t REG_EXPAND_SZ /d "%windir%\System32\cmd.exe /K pushd %%1 && %%USERPROFILE%%\miniconda3\Scripts\activate.bat"
REG ADD HKCR\LibraryFolder\background\shell\Anaconda\ /ve /f /d "Open in Anaconda"
REG ADD HKCR\LibraryFolder\background\shell\Anaconda\ /v Icon /f /t REG_EXPAND_SZ /d %%USERPROFILE%%\\miniconda3\\Menu\\Iconleak-Atrous-Console.ico
REG ADD HKCR\LibraryFolder\background\shell\Anaconda\command /f /ve /t REG_EXPAND_SZ /d "%windir%\System32\cmd.exe /K pushd %%v && %%USERPROFILE%%\miniconda3\Scripts\activate.bat"