1

I have a conda environment setup already.

I want to delete a few packages out of it, update few and add a few new packages.

currently, I am doing it manually one after another after source activate <my_exiting_conda>.

conda update x
conda update y
conda remove z --force
conda remove w --force
conda install -c <channel> <package name>

Is there any way using which I can put all these commands in a file and just use it to do all work at once.

Also when I run the above command manually, it asks to hit Y/n for each command? how can I avoid that?

Devesh Agrawal
  • 8,982
  • 16
  • 82
  • 131
  • Does this answer your question? [Conda - Silently installing a package](https://stackoverflow.com/questions/34644612/conda-silently-installing-a-package) – Mohnish Apr 23 '20 at 00:16
  • @Mohnish, yes it answers the second part. thanks. – Devesh Agrawal Apr 23 '20 at 00:18
  • you can use shell script to do them in one command 1. put the commands in a sh file e.g. auto_upddate.sh that contains conda update x -y and so on. 2. chmod +x auto_upddate.sh 3. $ ./auto_upddate.sh – Mohnish Apr 23 '20 at 00:35
  • awesome, that works.. thanks much – Devesh Agrawal Apr 23 '20 at 01:01
  • You can add and remove multiple packages at once: `conda remove -n my_existing_conda z w` – AMC Apr 24 '20 at 03:30

2 Answers2

0

Consider switching to using YAMLs to manage your envs and refrain from using conda update/install/remove commands. When you want to make multiple changes to an env, change them in the YAML, then use:

conda env update -f environment.yaml

This command also has the optional argument --prune which will remove any packages that are not required, i.e., provides the package deletion mechanism you seek.

Note that conda env commands do not provide a transaction review step. For that reason, I would not recommend using it to manage the base env.

Starting from Existing Env

To get a working YAML from an existing env (say foo), try running something like

conda env export -n foo --from-history > foo.yaml

The --from-history argument will only include the explicit specs that you've provided to the env, so the YAML will look closer to what one might make and maintain from scratch.

Note that if there were packages installed through pip they won't appear in the --from-history version. In that case, I would still begin from this version, then export a full YAML to capture any pip specs, and add them to the simpler version.

merv
  • 67,214
  • 13
  • 180
  • 245
0

Yes, you can pass packages in one go

conda update x y
conda remove z w --force
Prayson W. Daniel
  • 14,191
  • 4
  • 51
  • 57