Simplified MWE => Suppose I have Anaconda and do the following:
conda create -n demo python=3.6
conda activate demo
conda install seaborn
The last command installs 39 new packages including seaborn, matplotlib and pandas. Now suppose that time passes and I continue to set up my environment and wish to explicitly install matplotlib and pandas:
conda install matplotlib pandas
This tells me "All requested packages already installed", which is okay. Now however, if I decide I don't need seaborn anymore and remove it,
conda remove seaborn
this removes ALL 39 packages that were installed when seaborn was installed, including both matplotlib and pandas, which I explicitly installed after that! How can I avoid this problem?
My expected behaviour would be that conda remove seaborn removes seaborn and all of its dependencies, but does not remove any package (or dependencies thereof) that was explicitly installed before or after seaborn. Some might say just uninstall seaborn and all 39 packages, and then manually reinstall matplotlib and pandas. This works in trivial cases, but once there are e.g. 25 packages with complex interdependencies, this becomes very complicated, and at the very least a complete nuisance to maintain.
As a concrete example of this, how can I construct a full Anaconda environment minus a particular package and only the packages that depend on it? I tried:
conda create -n test python=3.6 anaconda
conda remove libtiff # I want this to strictly only remove libtiff and its recursive dependents, but obviously this is not what happens
but the second line removes essentially every single package in the entire environment as it removes anaconda. Any ideas?
I can't think of an automated way to do this, but if you absolutely must achieve this, then a hacky way to do it is:
Remove only the package(s) you want:
conda remove --force libtiff
Trigger a consistency check to get a list of now broken packages:
conda install -d python
If there are packages, then iterate (i.e., remove them with Step 1); otherwise, you're done.
Actually, you're not done because now every time you attempt a change in the environment, every package that isn't a dependency of an explicit spec will be proposed for removal. Probably the next step is to:
Export the resulting env:
conda env export -n my_env > env.yaml
Recreate the env:
conda env remove -n my_env
conda env create -n my_env -f env.yaml
Now all the packages will be explicit specs, which isn't necessarily a good thing either, but at least ensures they won't get removed on later updates.
Personally, I think this is a bad idea and don't really see the motivation. I think it is much better an idea to start from the packages you know you need, place them in a YAML definition, and create envs from that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With