Conda clean does not free disk space

Dear conda community,

I tried to install a cpu version of tensorflow on my anaconda installation on my home PC:

  1. Activated anaconda3 with eval "$(/home/username/anaconda3/bin/conda shell.bash hook)"
  2. conda create -n tf tensorflow
  3. Activated the new environment with conda activate tf.
  4. Installed a few more packages I needed to run a test code I created for the tensorflow test:
    conda install dask
    conda install -c conda-forge netcdf4
    conda install -c conda-forge xarray
    conda install -c conda-forge matplotlib
    pip3 install -U scikit-learn

In total, this took 3-4 GB of disk space. After my tensorflow tests were done, I intended to free up the disk space and remove the environment again.

  1. I removed the environment again with conda remove --name tf --all.

As expected, this doesn’t free disk space.

  1. Used conda clean --tarballs --packages --logfiles as this is supposed to free disk space.

Strangely, conda clean did not free disk space but I was actually robbed another 500 MB and had less disk space left than before conda clean.

Does someone know, what is happening and how I can actually free disk space of unused conda stuff? I want my disk space back.

I am using Windows Subsystem for Linux (Ubuntu 22.04.2 LTS) under Windows 11 22H2.

conda info yields

     active environment : base
    active env location : /home/username/anaconda3
            shell level : 1
       user config file : /home/username/.condarc
 populated config files :
          conda version : 23.1.0
    conda-build version : 3.23.3
         python version : 3.9.16.final.0
       virtual packages : __archspec=1=x86_64
                          __cuda=12.0=0
                          __glibc=2.35=0
                          __linux=5.10.16.3=0
                          __unix=0=0
       base environment : /home/username/anaconda3  (writable)
      conda av data dir : /home/username/anaconda3/etc/conda
  conda av metadata url : None
           channel URLs : https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /home/username/anaconda3/pkgs
                          /home/username/.conda/pkgs
       envs directories : /home/username/anaconda3/envs
                          /home/username/.conda/envs
               platform : linux-64
             user-agent : conda/23.1.0 requests/2.28.1 CPython/3.9.16 Linux/5.10.16.3-microsoft-standard-WSL2 ubuntu/22.04.1 glibc/2.35
                UID:GID : 1000:1000
             netrc file : None
           offline mode : False

Found a solution. The problem lies with the Windows subsystem for Linux (WSL):

On Windows 11 Home, I used the following to free at least some parts of the lost space again:

On a PowerShell, run as administrator, do:

  1. wsl --shutdown to shutdown the WSL
  2. wsl -l -v (to get the name of the WSL distribution)
(Get-ChildItem -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | Where-Object { $_.GetValue("DistributionName") -eq 'Ubuntu-22.04' }).GetValue("BasePath") + "\ext4.vhdx"

to print the path of the vhdx file that preoccupies / consumes disk space for WSL

  1. diskpart
  2. (note that behind “file=” the output from 3. must be written; example given below)
select vdisk file="C:\Users\username\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu22.04LTS_79rhkp1fndgsc\LocalState\ext4.vhdx"
  1. attach vdisk readonly
  2. compact vdisk
  3. detach vdisk
  4. exit
1 Like