Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install a package into multiple/all conda environments?

Tags:

python

conda

I'm using conda to run tests against different versions of python, numpy, etc., but there are some common dependencies for all combinations of python/numpy. Is there a way to install such packages into all conda environments, or do I have to specify each by hand?

like image 580
keflavich Avatar asked Jun 09 '14 09:06

keflavich


People also ask

How do I install packages in anaconda in another environment?

Go to Environments tab just below the Home tab and from there we can check what all packages are installed and what is not. It is very easy to install any package through anaconda navigator, simply search the required package, select package and click on apply to install it.

Can you have multiple conda environments?

I'd like to mention one more thing here. While you can have multiple environments that contain different versions of Python at the same time on the same computer, you can't set up 32- and 64-bit environments using the same Conda management system.

How do you import packages into a conda environment?

Usually you would open the anaconda navigator, then go to Enviroments on the left side, then at the bottom you would click "Add" to add a new enviroment. after that you click on the newly created enviroment and "open terminal". in that terminal you use: conda install -c anaconda numpy .

Can you pip install in a conda environment?

While still in beta, conda 4.6. 0 allows conda to consider pip installed packages and either replace these packages as needed or fulfill dependencies with the existing package.


2 Answers

You can run a shell loop over the output of conda env list. For example:

for env in $(conda env list | cut -d" " -f1 | tail -n+4); do conda install -n $env XXXXXX; done
like image 177
abalter Avatar answered Oct 19 '22 03:10

abalter


Instead of using a for loop in @abalter's answer, you can do it with xargs too. Note, this will only work for environment names without spaces:

conda env list | cut -d" " -f1 | tail -n+4 | xargs -L 1 conda install YOUR_PACKAGE -n
like image 26
Jannick Avatar answered Oct 19 '22 03:10

Jannick