I want to include activate.sh and deactivate.sh scripts in a Conda environment that is created for users when they do conda env create -f environment.yaml. Is there a way to have these scripts automatically copied into the $CONDA_PREFIX/etc/conda directory when it's created? Or do I need to write a script that creates the environment, and then copies the files manually?
- 8,571
- 7
- 41
- 80
1 Answers
Package reusable activation scripts
The Conda way to do this would be to bundle these files in a package (yes, a script-only package), ship it to a user channel on Anaconda Cloud, then have the package be installed as part of the YAML.
Example (and template)
Here's an example package I use: envvar-pythonusersite-true. Its only purpose is to set the PYTHONNOUSERSITE environment variable to true when the environment activates. The GitHub repository is a template, so simple to copy and I have some basic directions on what needs to be adjusted to ship it to a different Anaconda Cloud user channel.
The actual package is on my user site and can be used in a YAML like:
# omitting other stuff
dependencies:
- merv::envvar-pythonnousersite-true
If the script package is the only one from my channel, then I will use this explicit channel syntax (<channel>::), rather than add my channel to the channels: list.
Note that this example could technically have been a noarch: generic package, since it only delivers scripts. The .bat files will only run on Windows and the .sh could be edited to check handle Linux/macOS differences (though for environment variables, that isn't necessary).
- 67,214
- 13
- 180
- 245
-
That's a nice solution. Thank you. – Batman Jul 31 '23 at 17:02