In this blog we will understand how to perform various operations in the conda environment like conda delete environment,conda list environment,conda create an environment, etc. so let’s get started.
What is conda
Conda is an open-source package and environment management system. It was created to manage dependencies for Python programs but it can package and distribute software for any programming language.
Conda create environment
In this session, we will create a new conda virtual environment. The syntax for creating the virtual environment is
Conda create environment syntax
Syntax:
conda create --name <Virtual_environment_name>
Let’s use the above syntax to create a virtual environment called naive-skill
conda create --name naive-skill
Conda list environment
The user can verify the environment by typing the env list command.
conda env list
The conda env list command lists all the virtual environment that exists in your system.
Conda activate environment
Once the virtual environment is created, users need to activate it by typing the below command
conda activate naive-skill
In the command prompt, if the virtual environment name is visible, it means the environment is successfully activated.
Conda list all packages
Once you are inside the virtual environment, you can type the below command to list all the installed packages in the environment.
conda list
The above command lists all the packages available in the naive-skill environment.
Conda deactivate the current environment
If you are inside the virtual environment and you wish to deactivate it, then you can simply pass the below command to deactivate the current environment and change to the current environment which is base
conda deactivate
The above command deactivates the naive-skill virtual environment.
Conda delete environment
A user can use the conda remove command to remove the virtual environment completely and it will remove the installed packages as well.
Syntax of Conda delete environment
The conda delete environment command follows the below syntax
conda-env remove [-h] [-n ENVIRONMENT | -p PATH] [--experimental-solver {classic,libmamba,libmamba-draft}] [-d] [--json] [-q] [-v] [-y] Options: optional arguments: -h, --help Show this help message and exit. --experimental-solver {classic,libmamba,libmamba-draft} EXPERIMENTAL. Choose which solver backend to use. 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 Sets any confirmation values to 'yes' automatically. Users will not be asked to confirm any adding, deleting, backups, etc.
Now let’s use this command to remove the naive-skill virtual environment.
conda env remove --name naive-skill
Instead of –name, a user can also use the -n flag to remove the conda environment.
conda env remove -n naive-skill
Conda clone environment
conda also gives us the feature to create a clone of the existing virtual environment. This can be achieved by passing the –clone flag while creating the virtual environment.
Let’s create a virtual environment that is a clone of the naive-skill virtual environment.
conda create --name naive-skill-cloned --clone naive-skill
Conda activation issues
CommandNotFoundError: Your shell has not been properly configured to use ‘conda activate’
If you are getting the above error while creating the virtual environment then you need to follow the below steps
crate the virtual environment
conda create --name naive-skill
Source the bash
source activate base
activate virtual environment
conda activate naive-skill
Conclusion
I hope you liked this detailed tutorial on the conda delete environment. Please do let me know if you are facing any issues while following along.