conda: remove all installed packages from base?
$conda clean --all
by using this command you can remove old packages. and then delete all environment and reset the
If I remove a conda environment will it automatically remove all packages?
Let's be more specific and remove the env foo located at anaconda3/envs/foo
with
conda env remove -n foo
This usually deletes everything under anaconda3/envs/foo
.
PyPI packages may stick around. If you previously used pip install
in the environment, it can occasionally leave some residual things behind. If that's the case, you'll need to delete the anaconda3/envs/foo
folder manually after conda env remove
. Or you could try to pip uninstall
any PyPI packages first1, to get a clean conda env remove
result.
Conda also caches all packages, independent of whether or not they are currently in use. This would be under anaconda3/pkgs
(usually). To additionally delete the packages no longer in use, one can use
conda clean -tp # delete tarballs and unused packages
1: There is a command to programmatically remove all PyPI-installed packages from Conda environments in this answer.
Conda remove uninstalls more packages than expected
Workaround
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.
Commentary
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.
Conda remove all environments (except root)
Removing all directories inside the envs
subdirectory that resides inside conda
does the job. This is generally in your user folder ~
.
~\.conda\envs\
What is the difference between conda uninstall and conda remove?
There is no difference, they are the same command.
Check the help
output of conda uninstall
:
conda uninstall --help
usage: conda-script.py uninstall [-h] [-n ENVIRONMENT | -p PATH] [-c CHANNEL] [--use-local] [--override-channels]
[--repodata-fn REPODATA_FNS] [--all] [--features] [--force-remove] [--no-pin] [-C]
[-k] [--offline] [-d] [--json] [-q] [-v] [-y] [--dev]
[package_name [package_name ...]]
Alias for conda remove.
[...]
Note the Alias for conda remove.
Related Topics
How to Use Ffmpeg in a Python Function
Most Efficient Way to Forward-Fill Nan Values in Numpy Array
Get Current Url from Browser Using Python
How to Get the Latest File in a Folder
How to Get the Coordinates of the Bounding Box in Yolo Object Detection
Convert a Standard Python Key Value Dictionary List to Pyspark Data Frame
How to Make a Grade Calculator in Python
Python Number With 1000 Separator
Matplotlib Bar Chart: Space Out Bars
Get Rid of Columns With Null Value in Json Output
Pandas - Calculate Average of Columns With Condition Based on Values in Other Columns
Tf.Data.Dataset: How to Get the Dataset Size (Number of Elements in an Epoch)
How to Find the Unit Digits of a Specific Number
Sqlalchemy, Prevent Duplicate Rows
Python File Opens and Immediately Closes
Error Opening File in H5Py (File Signature Not Found)