Conda removes all environments (except root)

I know that I can delete one environment with

conda remove -n envname --all 

but I often create several new environments for installing a specification package or testing, so that I regularly finish working with 5-10 environments, and it pains me to delete them one after another. Is there an easy way (for Windows) to remove all environments except the root environment?

+5
source share
3 answers

Removing all directories inside the envs subdirectory inside conda does the job.

+5
source

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 
+1
source

Not the most elegant answer. But I would just copy the names of all environments with conda info --envs . Then create a bash file (or .bat for Windows) with all the necessary commands, for example ...

conda remove -n env_name_1 --all -y conda remove -n env_name_2 --all -y conda remove -n env_name_3 --all -y conda remove -n env_name_4 --all -y conda remove -n env_name_5 --all -y

Or just copy and paste this into the terminal and it will sort you!

If I were a little bash (or .bat) wizard (or could be bothered by doing some kind of Google search), you could output the output from conda info --envs to generate the conda remove ... commands.

+1
source

Source: https://habr.com/ru/post/1244210/


All Articles