Explain Codes LogoExplain Codes Logo

Removing Conda environment

python
conda
environment-management
version-control
Alex KataevbyAlex Kataev·Oct 31, 2024
TLDR

The quick and dirty for deleting a Conda environment is to run the command conda env remove --name env_name. Swap env_name with the name of the environment you want to remove, like this:

conda env remove --name env_name

Voila! The environment and all its dependencies are uninstalled from Conda.

Pre-removal checklist

Like a surgeon prepping for operation, clearing the environment is key. Deactivate the Conda environment with:

conda deactivate

Confirm there are no lingering sessions or running shells with the environment. If you're unable to deactivate, open a new shell to cut all ties. It's like breaking up - clean and clear.

Cleanup

Expecting a complete wipeout but found some stragglers? Check the anaconda3/envs directory for leftovers and remove them manually. It's like cleaning under the couch, you never know what you'll find. Stuck? Try a Conda upgrade:

conda install -n base -c defaults conda # Tip: it's always good to have the latest and greatest!

Version control

Version control is not only for programmers! It's a lifesaver for your Conda environments too. Pin to a specific Conda version to avoid possible clashes:

conda install conda=4.9.2 # Why 4.9.2? Why not! 😉

Customize your workspace

Looking for more options? Create your Conda environment with a custom path using -p:

conda create -p /path/to/custom_env

Think of it as your personal workspace, with a coffee machine and all. ☕

Switching environments

Since Conda 4.6 release you can use conda activate to jump between environments like a pro. Remember to conda deactivate to ensure you're back to the base level before wiping the slate clean.

Post-removal audit

Deleted your environment? Do a roll call with conda info --envs to confirm. It's like checking the closet after watching a horror movie - better safe than sorry:

conda info --envs

Pro-tips

Before running the removal command, confirm you have the admin rights to prevent permission obstructions. Do a quick directory check before removal to avoid any "I can't delete the folder because I'm in it" situations.