Sunday, September 4, 2022

[SOLVED] Removing conda virtual environment created outside the default /envs folder of anaconda

Issue

For a specific python project and to save space in the C-drive, I created a conda virtual environment inside my main project folder which was in D-drive using the command

conda create --prefix ./envs

Which created the envs folder/environment inside the project folder. Now after completing my project I want to delete that environment to save memory. I used the

conda env list

to see the list of envs and there only the path of that environment that I created is showing as

# conda environments:
#
base                     C:\Users\Karthik\anaconda3        
                      *  D:\DLCVNLP\ANN-implementation\envs

How to delete that environment completely along with packages that I installed in that env for the project?. Should I manually delete the \envs folder or is there a way to do that using command line. I need a safer way of doing this so that by deleting this I don't have any issues with the base environment.


Solution

In the future, please use the --help flag to consult documentation. In this case, see

$ conda env remove --help
usage: conda-env remove [-h] [-n ENVIRONMENT | -p PATH] [-d] [--json] [-q] [-v] [-y]

Remove an environmentRemoves a provided environment.  You must deactivate the existing
environment before you can remove it.

Options:

optional arguments:
  -h, --help            Show this help message and exit.

Target Environment Specification:
  -n ENVIRONMENT, --name ENVIRONMENT
                        Name of environment.
  -p PATH, --prefix PATH
                        Full path to environment location (i.e. prefix).

Output, Prompt, and Flow Control Options:
  -d, --dry-run         Only display what would have been done.
  --json                Report all output as json. Suitable for using conda programmatically.
  -q, --quiet           Do not display progress bar.
  -v, --verbose         Can be used multiple times. Once for INFO, twice for DEBUG, three
                        times for TRACE.
  -y, --yes             Do not ask for confirmation.

Examples:

    conda env remove --name FOO
    conda env remove -n FOO

Specifically, there is a -p, --prefix flag for removing unnamed environments, like:

conda env remove -p D:\DLCVNLP\ANN-implementation\envs


Answered By - merv
Answer Checked By - Terry (WPSolving Volunteer)