Adding "Open Anaconda Prompt here" to context menu (Windows) Adding "Open Anaconda Prompt here" to context menu (Windows) windows windows

Adding "Open Anaconda Prompt here" to context menu (Windows)


In recent Anaconda versions (I'm at conda 4.5.5) they have changed the behaviour and the shortcut to Anaconda Prompt, so the new procedure is in fact a bit simpler than described by bdforbes.

The new way to launch Anaconda Prompt in a folder is

cmd.exe /K %%USERPROFILE%%\AppData\Local\Continuum\Anaconda3\Scripts\activate.bat

pushd is to change the current directory, %V is the current directory, and /K is to run a command.

So the modified cwp2.py is not needed anymore. Put the following contents in a .bat-file and run as administrator to add the needed keys to the registry (a modified version of the gist posted by Thibaud Ruelle in the comments to the other answer)

REG ADD HKCR\Directory\Background\shell\Anaconda\ /ve /f /d "Anaconda Prompt Here"REG ADD HKCR\Directory\Background\shell\Anaconda\ /v Icon /f /t REG_EXPAND_SZ /d %%USERPROFILE%%\\Anaconda3\\Menu\\Iconleak-Atrous-Console.icoREG ADD HKCR\Directory\Background\shell\Anaconda\command /f /ve /t REG_EXPAND_SZ /d "%windir%\System32\cmd.exe pushd "%V" "/K" %%USERPROFILE%%\Anaconda3\Scripts\activate.bat %%USERPROFILE%%\Anaconda3"REG ADD HKCR\Directory\shell\Anaconda\ /ve /f /d "Anaconda Prompt Here"REG ADD HKCR\Directory\shell\Anaconda\ /v Icon /f /t REG_EXPAND_SZ /d %%USERPROFILE%%\\Anaconda3\\Menu\\Iconleak-Atrous-Console.icoREG ADD HKCR\Directory\shell\Anaconda\command /f /ve /t REG_EXPAND_SZ /d "%windir%\System32\cmd.exe pushd "%V" "/K" %%USERPROFILE%%\Anaconda3\Scripts\activate.bat %%USERPROFILE%%\Anaconda3"


UPDATE: The answer by Filip S. might work better on more recent versions of Anaconda.

ANOTHER UPDATE: I fixed an issue with using this launcher in the drive root (e.g. C:\ or D:\). It's very minor: some whitespace has been added to the registry entry (relevant part: "%V ") so that the trailing backslash does not confuse Windows.

Original post

I also wanted this functionality, so I made it.The key steps are outlined below, with the explanation further down.

Solution

Warning: Do not proceed unless you are comfortable editing the registry and are using a non-production system. And obviously don't run everything I tell you to, check that it's not doing anything nefarious. You don't know me!

1. Modify the Anaconda script that sets the working directory

Find the Anaconda script cwp.py (mine was in C:\Users\bdforbes\Anaconda3\) and copy it to cwp2.py in the same directory.

Modify cwp2.py to accept a target path as the second argument and change to that directory:

prefix = sys.argv[1]cwd = sys.argv[2]args = sys.argv[3:]... (PATH setting code)(REMOVE OLD LOGIC THAT CALLED os.chdir)os.chdir(cwd)sys.exit(subprocess.call(args, env=env))

Full code here: https://gist.github.com/bdforbes/9ef59cd01c22acefc20c5c92bd9550ae

2. Add the registry keys

In the registry, go to HKEY_CLASSES_ROOT\Directory\Background\shell\ and add a key Anaconda with default value "Open Anaconda Prompt Here", with a sub-key command with the following default value:

C:\Users\bdforbes\Anaconda3\pythonw.exe C:\Users\bdforbes\Anaconda3\cwp2.py C:\Users\bdforbes\Anaconda3 "%V " cmd.exe "/K" C:\Users\bdforbes\Anaconda3\Scripts\activate.bat C:\Users\bdforbes\Anaconda3

Add the same entries to HKEY_CLASSES_ROOT\Directory\shell\.

I've put a .reg file here, you just need to search replace bdforbes and replace it with your Windows account name. Don't run a .reg file without checking it first!

enter image description hereenter image description here

3. Use your fancy new context menu item

Right click on a folder. You should see the new entry there which will let you open a new Anaconda prompt.

enter image description here


  1. Run Registry Editor (regedit.exe)
  2. Go to HKEY_CLASSES_ROOT > Directory > Background > shell
  3. Add a key named AnacondaPrompt and set its value to Anaconda Prompt Here
  4. Add a key under this key called command, and set its value to cmd.exe /K C:\Users\user\Anaconda3\Scripts\activate.bat change the location to wherever your Anaconda installation is located.