According to my comment, you can get all environments with a single conda command, and then try to view it and delete them separately. Here is one way to do something like this. Note that you must replace anaconda_command_prompt_string
with the appropriate line that the Anaconda command line will invoke. Also this code is probably pretty fragile:
from subprocess import PIPE, Popen anaconda_command_prompt_string = 'C:\\Windows\\system32\\cmd.exe "/K" C:\\Users\\your_user_name\\AppData\\Local\\Continuum\\Anaconda3\\Scripts\\activate.bat C:\\Users\\your_user_name\\AppData\\Local\\Continuum\\Anaconda3' p = Popen(anaconda_command_prompt_string, stdin=PIPE, stdout=PIPE, bufsize=1) p.stdout.readline(), # read the first line print >>p.stdin, 'conda env list' # write input p.stdin.flush() p.stdout.readline() p.stdout.readline() p.stdout.readline() p.stdout.readline() envs = [] line = 'Anaconda' while 'Anaconda' in line: line = p.stdout.readline() name = line.replace(' ', '').split('C:')[0] if 'root' not in name and '\n' not in name: envs.append(name) for name in envs: command_string = 'conda remove -n {0} --all --yes'.format(name) print >>p.stdin, command_string p.stdin.flush() line = p.stdout.readline() while 'Complete' not in line: print line line = p.stdout.readline() print line
source share