Just came across this post about specifying parameters on conda
Basically, when you create an enter a new environment, this gives you the capability to save environmental variables specific to that environment. And even better, you can deconstruct those variables once you leave that environment.
What does this mean? It means that you can enforce relatively isolated environments, when it comes to environments. So if you wanted to install 2 different versions of the same package in two different environments, easy! Just specify the path variables that you want under the activate.d file, and restore the variables that you had previously in the deactivate.d file.
To see what I mean, consider the following test
Now we have a new conda environment, and if you check out your miniconda envs folder you should be able to see it. For me, I can run the following to do this
I'm using miniconda instead because anaconda has a lot of bloatware bundled with it, which can hamper the installation process of some programs. See my previous post about installing qiime for more details.
Now within your test environment, you can create scripts to store all of your environmental variables.
The conda tutorial I pointed to above pretty much does this
Now, within your activate.d file, you can create an entirely new path. This should work assuming that you don't already have a variable named OLD_PATH.
And in your deactivate.d file you can restore your original environment variable
Try echoing out these variables, and you should see that your PATH variable should be changed in the test environment. It just goes to show, conda is a really powerful tool.
Basically, when you create an enter a new environment, this gives you the capability to save environmental variables specific to that environment. And even better, you can deconstruct those variables once you leave that environment.
What does this mean? It means that you can enforce relatively isolated environments, when it comes to environments. So if you wanted to install 2 different versions of the same package in two different environments, easy! Just specify the path variables that you want under the activate.d file, and restore the variables that you had previously in the deactivate.d file.
To see what I mean, consider the following test
conda create -n test pip source activate test
Now we have a new conda environment, and if you check out your miniconda envs folder you should be able to see it. For me, I can run the following to do this
ls ~/miniconda3/envs/
I'm using miniconda instead because anaconda has a lot of bloatware bundled with it, which can hamper the installation process of some programs. See my previous post about installing qiime for more details.
Now within your test environment, you can create scripts to store all of your environmental variables.
mkdir -p ~/miniconda3/envs/test/etc/conda/activate.d
mkdir -p ~/miniconda3/envs/test/etc/conda/deactivate.d
touch ~/miniconda3/envs/test/etc/conda/activate.d/env_vars.sh
touch ~/miniconda3/envs/test/etc/conda/deactivate.d/env_vars.sh
The conda tutorial I pointed to above pretty much does this
Now, within your activate.d file, you can create an entirely new path. This should work assuming that you don't already have a variable named OLD_PATH.
#!/bin/sh export OLD_PATH=$PATH export PATH='foo'
And in your deactivate.d file you can restore your original environment variable
#!/bin/sh export PATH=$OLD_PATH unset OLDPATH
Try echoing out these variables, and you should see that your PATH variable should be changed in the test environment. It just goes to show, conda is a really powerful tool.
Comments
Post a Comment