diff --git a/Python/QA-003-Conda-Environment.ipynb b/Python/QA-003-Conda-Environment.ipynb index 9d06d0bf1bbd6f462ff3b875c16dd6f5969178bd..7786f777968b6f978140cb215f9ed89cf72b9194 100644 --- a/Python/QA-003-Conda-Environment.ipynb +++ b/Python/QA-003-Conda-Environment.ipynb @@ -4,7 +4,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Setting up a user environment with conda\n" + "# Setting up a user environment\n", + "\n", + "Topics\n", + "* Setup a user environment [using conda](#using-conda)\n", + " - [Add user environment to notebook kernels](#add-the-new-environment-to-your-active-kernels)\n", + " - [Activate your conda environment](#activate-your-conda-environment)\n", + "* Setup a user environment [using venv](#using-virtual-environment)\n", + "* Include `PATH` in [Notebook Kernel](#add-path-to-your-user-environment)\n" ] }, { @@ -26,6 +33,13 @@ "!module list" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Using conda" + ] + }, { "cell_type": "code", "execution_count": 2, @@ -231,6 +245,31 @@ "!~/.conda/envs/myenv/bin/python -m ipykernel install --user --name MYENV --display-name \"Py3.7\"" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Activate your conda environment\n", + "Conda Environments need to be added to the `PATH` to work well. So there is an `activate` function for these conda environments.\n", + "\n", + "However, running\n", + "```bash\n", + "conda init bash\n", + "```\n", + "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", + "\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", + "# now activating the environment works\n", + "conda activate myenv\n", + "```" + ] + }, { "cell_type": "code", "execution_count": 5, @@ -255,7 +294,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Custom Environment Python Environment" + "## Using virtual environment" ] }, { @@ -351,6 +390,34 @@ "!jupyter kernelspec list" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Add PATH to your user environment\n", + "\n", + "In order to get full access to all tools installed in your local environment, add it to your `PATH`.\n", + "\n", + "Open your `kernel.json` file located `/jetfs/home/mblaschek/.local/share/jupyter/kernels/myenv/kernel.json`:\n", + "```json\n", + "{\n", + " \"argv\": [\n", + " \"/jetfs/home/mblaschek/.conda/envs/myenv/bin/python\",\n", + " \"-m\",\n", + " \"ipykernel_launcher\",\n", + " \"-f\",\n", + " \"{connection_file}\"\n", + " ],\n", + " \"env\" : {\n", + " \"PATH\": \"/jetfs/home/mblaschek/.conda/envs/myenv/bin/:${PATH}\",\n", + " \"LD_LIBRARY_PATH\": \"/jetfs/home/mblaschek/.conda/envs/myenv/lib:${LD_LIBRARY_PATH}\"\n", + " },\n", + " \"display_name\": \"MYENV\",\n", + " \"language\": \"python\"\n", + "}\n", + "```" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -361,7 +428,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Miniconda3 (4.8.2)", + "display_name": "Anaconda3 (2020.07)", "language": "python", "name": "python3" }, @@ -375,7 +442,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.1" + "version": "3.8.3" } }, "nbformat": 4,