1

Conda environments are defined by the packages installed in them and extra metadata like which channels to use, channel priority, the subdir (whether to use osx-64 or osx-arm).

I would like to uninstall only the packages but keep the environment configuration alive.

I know I can delete the entire environment with conda remove --all -n ENV_NAME - but using this command I loose the metadata.

It is quite likely that no conda CLI command exists to do what I want (at least conda remove doesn't seem to do this). But is there a workaround, maybe listing all packages and feeding them to conda remove -n ENV_NAME [PACKAGE_NAME ...].

I opened a feature request to add an option to keep empty environments around: https://github.com/conda/conda/issues/12485

Cornelius Roemer
  • 3,772
  • 1
  • 24
  • 55

1 Answers1

1

With a little help from our friends...

mamba list | grep -v '#' | awk '{print $1}' | xargs mamba remove -d

⚠️ The -d flag is added for safety, since otherwise this will not prompt user for review! Remove it to execute. Use at your own risk.

merv
  • 67,214
  • 13
  • 180
  • 245
  • Nice! So `mamba` only removes the packages, not the environment? I get an error when I run this, due to `__osx` and `__unix` special packages: `KeyError: PackageRecord(_hash=-472553835912562056, name='__osx', version='13.2.1', build='0', build_number=0, channel=Channel("@"), subdir='osx-64', fn='__osx', md5='12345678901234567890123456789012', package_type='virtual_system')` – Cornelius Roemer Mar 14 '23 at 20:01
  • This lists out all the packages and asks to remove them - `conda` should have same behavior. If mutex packages are a problem, maybe use grep to skip them, e.g., `grep -v '^[#_]'`. – merv Mar 14 '23 at 21:01