conda-forge / miniforge

A conda-forge distribution.
https://conda-forge.org/miniforge
Other
5.76k stars 306 forks source link

Remove environment failed with "CondaEnvironmentError: cannot remove current environment." with Anaconda + miniforge installed #521

Closed orionlee closed 7 months ago

orionlee commented 7 months ago

Solution to issue cannot be found in the documentation.

Issue

I have been using Anaconda and just installed miniforge3 as well.

After miniforge3 installation, removing an environment with conda remove <env> --all consistently failed with CondaEnvironmentError: cannot remove current environment., even though no environment was activated at all.

It happened to both miniforge3 (with miniforge3 created environments) and the old Anaconda (with Anaconda created environments).

A workaround is to use conda remove --prefix instead:

conda remove --prefix c:\pkg\_winNonPortables\miniforge3\envs\foobar --all

Installed packages

# packages in environment at c:\pkg\_winNonPortables\miniforge3:
#
# Name                    Version                   Build  Channel
archspec                  0.2.2              pyhd8ed1ab_0    conda-forge
boltons                   23.0.0             pyhd8ed1ab_0    conda-forge
brotli-python             1.0.9           py310h00ffb61_9    conda-forge
bzip2                     1.0.8                h8ffe710_4    conda-forge
ca-certificates           2023.11.17           h56e8100_0    conda-forge
certifi                   2023.11.17         pyhd8ed1ab_0    conda-forge
cffi                      1.15.1          py310h628cb3f_3    conda-forge
charset-normalizer        3.2.0              pyhd8ed1ab_0    conda-forge
colorama                  0.4.6              pyhd8ed1ab_0    conda-forge
conda                     23.10.0         py310h5588dad_1    conda-forge
conda-libmamba-solver     23.11.1            pyhd8ed1ab_0    conda-forge
conda-package-handling    2.2.0              pyh38be061_0    conda-forge
conda-package-streaming   0.9.0              pyhd8ed1ab_0    conda-forge
cryptography              41.0.3          py310h6e82f81_0    conda-forge
fmt                       10.1.1               h181d51b_0    conda-forge
idna                      3.4                pyhd8ed1ab_0    conda-forge
jsonpatch                 1.32               pyhd8ed1ab_0    conda-forge
jsonpointer               2.0                        py_0    conda-forge
krb5                      1.21.2               heb0366b_0    conda-forge
libarchive                3.7.2                h6f8411a_0    conda-forge
libcurl                   8.4.0                hd5e4a3a_0    conda-forge
libffi                    3.4.2                h8ffe710_5    conda-forge
libiconv                  1.17                 h8ffe710_0    conda-forge
libmamba                  1.5.3                h3f09ed1_2    conda-forge
libmambapy                1.5.3           py310h04f2035_2    conda-forge
libsolv                   0.7.24               h12be248_1    conda-forge
libsqlite                 3.42.0               hcfcfb64_0    conda-forge
libssh2                   1.11.0               h7dfc565_0    conda-forge
libxml2                   2.11.5               hc3477c8_0    conda-forge
libzlib                   1.2.13               hcfcfb64_5    conda-forge
lz4-c                     1.9.4                hcfcfb64_0    conda-forge
lzo                       2.10              he774522_1000    conda-forge
mamba                     1.5.3           py310hd9d798f_2    conda-forge
menuinst                  1.4.19          py310h5588dad_1    conda-forge
miniforge_console_shortcut 1.0                  h57928b3_0    conda-forge
openssl                   3.1.4                hcfcfb64_0    conda-forge
packaging                 23.1               pyhd8ed1ab_0    conda-forge
pip                       23.2.1             pyhd8ed1ab_0    conda-forge
pluggy                    1.2.0              pyhd8ed1ab_0    conda-forge
pybind11-abi              4                    hd8ed1ab_3    conda-forge
pycosat                   0.6.4           py310h8d17308_1    conda-forge
pycparser                 2.21               pyhd8ed1ab_0    conda-forge
pyopenssl                 23.2.0             pyhd8ed1ab_1    conda-forge
pysocks                   1.7.1              pyh0701188_6    conda-forge
python                    3.10.12         h4de0772_0_cpython    conda-forge
python_abi                3.10                    3_cp310    conda-forge
reproc                    14.2.4               hcfcfb64_0    conda-forge
reproc-cpp                14.2.4               h63175ca_0    conda-forge
requests                  2.31.0             pyhd8ed1ab_0    conda-forge
ruamel.yaml               0.17.32         py310h8d17308_0    conda-forge
ruamel.yaml.clib          0.2.7           py310h8d17308_1    conda-forge
setuptools                68.1.2             pyhd8ed1ab_0    conda-forge
tk                        8.6.12               h8ffe710_0    conda-forge
toolz                     0.12.0             pyhd8ed1ab_0    conda-forge
tqdm                      4.66.1             pyhd8ed1ab_0    conda-forge
truststore                0.8.0              pyhd8ed1ab_0    conda-forge
tzdata                    2023c                h71feb2d_0    conda-forge
ucrt                      10.0.22621.0         h57928b3_0    conda-forge
urllib3                   2.0.4              pyhd8ed1ab_0    conda-forge
vc                        14.3                h64f974e_17    conda-forge
vc14_runtime              14.36.32532         hfdfe4a8_17    conda-forge
vs2015_runtime            14.36.32532         h05e6639_17    conda-forge
wheel                     0.41.1             pyhd8ed1ab_0    conda-forge
win_inet_pton             1.1.0              pyhd8ed1ab_6    conda-forge
xz                        5.2.6                h8d14728_0    conda-forge
yaml-cpp                  0.8.0                h63175ca_0    conda-forge
zstandard                 0.22.0          py310h0009e47_0    conda-forge
zstd                      1.5.5                h12be248_0    conda-forge

Environment info

active environment : None
            shell level : 0
       user config file : C:\Users\SL\.condarc
 populated config files : c:\pkg\_winNonPortables\miniforge3\.condarc
                          C:\Users\SL\.condarc
          conda version : 23.10.0
    conda-build version : not installed
         python version : 3.10.12.final.0
       virtual packages : __archspec=1=x86_64
                          __cuda=11.6=0
                          __win=0=0
       base environment : c:\pkg\_winNonPortables\miniforge3  (writable)
      conda av data dir : c:\pkg\_winNonPortables\miniforge3\etc\conda
  conda av metadata url : None
           channel URLs : https://conda.anaconda.org/conda-forge/win-64
                          https://conda.anaconda.org/conda-forge/noarch
                          https://conda.anaconda.org/pytorch/win-64
                          https://conda.anaconda.org/pytorch/noarch
                          https://repo.anaconda.com/pkgs/main/win-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/win-64
                          https://repo.anaconda.com/pkgs/r/noarch
                          https://repo.anaconda.com/pkgs/msys2/win-64
                          https://repo.anaconda.com/pkgs/msys2/noarch
          package cache : c:\pkg\_winNonPortables\miniforge3\pkgs
                          C:\Users\SL\.conda\pkgs
                          C:\Users\SL\AppData\Local\conda\conda\pkgs
       envs directories : c:\pkg\_winNonPortables\miniforge3\envs
                          C:\Users\SL\.conda\envs
                          C:\Users\SL\AppData\Local\conda\conda\envs
               platform : win-64
             user-agent : conda/23.10.0 requests/2.31.0 CPython/3.10.12 Windows/10 Windows/10.0.22621 solver/libmamba conda-libmamba-solver/23.11.1 libmambapy/1.5.3
          administrator : False
             netrc file : None
           offline mode : False
orionlee commented 7 months ago

My bad! I tried to remove an environment incorrectly with conda remove <env> --all, it should be conda remove -n <env> --all