From 32e39ea78759504ad86cea28234e3e356fc4f98c Mon Sep 17 00:00:00 2001 From: Michael Blaschek <michael.blaschek@univie.ac.at> Date: Wed, 1 Dec 2021 11:43:25 +0100 Subject: [PATCH] conda activate function revised! --- Python/QA-003-Conda-Environment.ipynb | 32 ++++++++++++++++++++--- Python/Your-First-Notebook-onJet_v2.ipynb | 29 +++++++++++++++++--- 2 files changed, 54 insertions(+), 7 deletions(-) diff --git a/Python/QA-003-Conda-Environment.ipynb b/Python/QA-003-Conda-Environment.ipynb index cc8118b..ecd5845 100644 --- a/Python/QA-003-Conda-Environment.ipynb +++ b/Python/QA-003-Conda-Environment.ipynb @@ -259,14 +259,38 @@ "will edit your `.bashrc` and that is not nice, especially when you might move to another module. \n", "**Therefore this is not recommended to do.**\n", "\n", - "In order to use your environment in a shell script or on a slurm job, try the following:\n", + "This script is used by `conda init bash` to set the configuration, we simply source (load) it and get the same functionality as we would be using `conda init bash`. **(Do not use `conda init bash`)**\n", "\n", - "Load the shell setup script located in the conda source tree (`${CONDA_ROOT}/etc/profile.d/conda.sh`) and activate your environment:\n", "```bash\n", - "# Load from the current conda module the BASH functionality (as in activate)\n", - "source $(which conda)/../etc/profile.d/conda.sh\n", + "source $(dirname $(which conda))/../etc/profile.d/conda.sh\n", "# now activating the environment works\n", "conda activate myenv\n", + "```\n", + "\n", + "#### bash conda_activate function\n", + "optionaly you can add this bash function to your `.bashrc` for convenience:\n", + "\n", + "```bash\n", + "conda_activate(){\n", + " if ! command -v conda &> /dev/null; then\n", + " echo \"Load ana/miniconda module first\"\n", + " else\n", + " if [ $# -ne 1 ]; then\n", + " echo \"usage: conda_activate [env-name]\"\n", + " \n", + " else\n", + " source $(dirname $(which conda))/../etc/profile.d/conda.sh\n", + " conda activate $1\n", + " fi\n", + " fi\n", + "}\n", + "```\n", + "\n", + "After your `.bashrc` has been loaded (e.g. logout/login again) you should be able to use\n", + "\n", + "```bash\n", + "module load anaconda3\n", + "conda_activate myenv\n", "```" ] }, diff --git a/Python/Your-First-Notebook-onJet_v2.ipynb b/Python/Your-First-Notebook-onJet_v2.ipynb index 5d37966..3105d22 100644 --- a/Python/Your-First-Notebook-onJet_v2.ipynb +++ b/Python/Your-First-Notebook-onJet_v2.ipynb @@ -575,13 +575,36 @@ "\n", "Hint: Checkout the guides on [Gitlab](https://gitlab.phaidra.org/imgw/computer-resources/-/blob/master/Python/QA-003-Conda-Environment.ipynb#Activate-your-conda-environment)\n", "\n", - "### Load from the current conda module the BASH functionality (as in activate)\n", + "### Load bash conda configuration\n", + "This script is used by `conda init bash` to set the configuration, we simply source (load) it and get the same functionality as we would be using `conda init bash`. **(Do not use `conda init bash`)**\n", "\n", - "```sh\n", - "source $(which conda)/../etc/profile.d/conda.sh\n", + "```bash\n", + "source $(dirname $(which conda))/../etc/profile.d/conda.sh\n", "# now activating the environment works\n", "conda activate myenv\n", "```\n", + "optionaly you can add this bash function to your `.bashrc` for convenience:\n", + "```bash\n", + "conda_activate(){\n", + " if ! command -v conda &> /dev/null; then\n", + " echo \"Load ana/miniconda module first\"\n", + " else\n", + " if [ $# -ne 1 ]; then\n", + " echo \"usage: conda_activate [env-name]\"\n", + " \n", + " else\n", + " source $(dirname $(which conda))/../etc/profile.d/conda.sh\n", + " conda activate $1\n", + " fi\n", + " fi\n", + "}\n", + "```\n", + "After your `.bashrc` has been loaded (e.g. logout/login again) you should be able to use\n", + "\n", + "```bash\n", + "module load anaconda3\n", + "conda_activate myenv\n", + "```\n", "\n", "### Activate your kernel in your notebooks\n", "\n", -- GitLab