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!
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.