Protect conda environments to avoid mistakenly modifying them.
In conda, it's sometimes nice to set certain environments as "off-limits". This can especially be true for the base environment. This plugin that allows you to protect arbitrary environments, and it will cause conda to exit early on the following commands if an environment is protected:
- install
- create
- update
- remove
- env remove
- env update (still not fully supported)
You can install this plugin by running the following command:
conda install -c conda-forge conda-protect
Conda protect installs several new subcommands for conda: one for protecting environments protect
and one for listing guarded environments plist
. These commands are explained in further
detail below:
To guard an environment, run the protect
subcommand:
$ conda protect base
base is 🔐 protected
Now, when you try to run a command against this environment, conda will exit early:
$ conda install -n base python
CondaProtectError: Environment "base" is currently protected. Run `conda protect 'base'` to remove protection.
If you want to remove a protection to add/modify anything, just run the protect
subcommand again:
$ conda protect base
base is unprotected 🔓
Conda protect also installs a plist
subcommand that comes in handy when you've forgotten which
environments are protected:
$ conda protect --list
Conda Environments
┏━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
┃ Name ┃ Prefix ┃ Status ┃
┡━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━┩
│ - │ /tmp/user1-test-env-one │ 🔐 protected │
│ base │ /home/user1/opt/conda/ │ 🔐 protected │
│ test_env1 │ /home/user1/opt/conda/envs/test_env1 │ 🔐 protected │
│ test_env2 │ /home/user1/opt/conda/envs/test_env2 │ │
│ test_env3 │ /home/user1/opt/conda/envs/test_env3 │ │
└───────────┴───────────────────────────────────────┴──────────────┘
You can also list just the protected environments with the --protected
option:
$ conda protect --list --protected
Conda Environments
┏━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
┃ Name ┃ Prefix ┃ Status ┃
┡━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━┩
│ - │ /tmp/user1-test-env-one │ 🔐 protected │
│ base │ /home/user1/opt/conda/ │ 🔐 protected │
│ test_env1 │ /home/user1/opt/conda/envs/test_env1 │ 🔐 protected │
└───────────┴───────────────────────────────────────┴──────────────┘