From 8eaa2f888536fab9d743008e1ff8362675ac0a9a Mon Sep 17 00:00:00 2001
From: Michael Blaschek <michael.blaschek@univie.ac.at>
Date: Tue, 24 Nov 2020 17:43:01 +0100
Subject: [PATCH] Upload New File

---
 Python/QA-003-Conda-Environment.ipynb | 383 ++++++++++++++++++++++++++
 1 file changed, 383 insertions(+)
 create mode 100644 Python/QA-003-Conda-Environment.ipynb

diff --git a/Python/QA-003-Conda-Environment.ipynb b/Python/QA-003-Conda-Environment.ipynb
new file mode 100644
index 0000000..9d06d0b
--- /dev/null
+++ b/Python/QA-003-Conda-Environment.ipynb
@@ -0,0 +1,383 @@
+{
+ "cells": [
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "# Setting up a user environment with conda\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 1,
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Currently Loaded Modulefiles:\u001b[m\n",
+      " 1) miniconda3/4.8.2-gcc-8.3.1-3m7b6t2  \u001b[m\n",
+      "\u001b[K\u001b[?1l\u001b>"
+     ]
+    }
+   ],
+   "source": [
+    "!module list"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "\n",
+      "     active environment : None\n",
+      "       user config file : /jetfs/home/mblaschek/.condarc\n",
+      " populated config files : /jetfs/home/mblaschek/.condarc\n",
+      "          conda version : 4.8.5\n",
+      "    conda-build version : not installed\n",
+      "         python version : 3.8.1.final.0\n",
+      "       virtual packages : __glibc=2.28\n",
+      "       base environment : /jetfs/spack/opt/spack/linux-rhel8-skylake_avx512/gcc-8.3.1/miniconda3-4.8.2-3m7b6t2kgedyr3jnd2nasmgiq7wm27iv  (read only)\n",
+      "           channel URLs : https://repo.anaconda.com/pkgs/main/linux-64\n",
+      "                          https://repo.anaconda.com/pkgs/main/noarch\n",
+      "                          https://repo.anaconda.com/pkgs/r/linux-64\n",
+      "                          https://repo.anaconda.com/pkgs/r/noarch\n",
+      "          package cache : /jetfs/spack/opt/spack/linux-rhel8-skylake_avx512/gcc-8.3.1/miniconda3-4.8.2-3m7b6t2kgedyr3jnd2nasmgiq7wm27iv/pkgs\n",
+      "                          /jetfs/home/mblaschek/.conda/pkgs\n",
+      "       envs directories : /jetfs/home/mblaschek/.conda/envs\n",
+      "                          /jetfs/spack/opt/spack/linux-rhel8-skylake_avx512/gcc-8.3.1/miniconda3-4.8.2-3m7b6t2kgedyr3jnd2nasmgiq7wm27iv/envs\n",
+      "               platform : linux-64\n",
+      "             user-agent : conda/4.8.5 requests/2.22.0 CPython/3.8.1 Linux/4.18.0-147.el8.x86_64 centos/8.2.2004 glibc/2.28\n",
+      "                UID:GID : 54212:100\n",
+      "             netrc file : None\n",
+      "           offline mode : False\n",
+      "\n"
+     ]
+    }
+   ],
+   "source": [
+    "!conda info"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 3,
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Collecting package metadata (current_repodata.json): done\n",
+      "Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.\n",
+      "Collecting package metadata (repodata.json): done\n",
+      "Solving environment: done\n",
+      "\n",
+      "\n",
+      "==> WARNING: A newer version of conda exists. <==\n",
+      "  current version: 4.8.5\n",
+      "  latest version: 4.9.2\n",
+      "\n",
+      "Please update conda by running\n",
+      "\n",
+      "    $ conda update -n base -c defaults conda\n",
+      "\n",
+      "\n",
+      "\n",
+      "## Package Plan ##\n",
+      "\n",
+      "  environment location: /jetfs/home/mblaschek/.conda/envs/myenv\n",
+      "\n",
+      "  added / updated specs:\n",
+      "    - ipykernel\n",
+      "    - numpy\n",
+      "    - python=3.7\n",
+      "\n",
+      "\n",
+      "The following packages will be downloaded:\n",
+      "\n",
+      "    package                    |            build\n",
+      "    ---------------------------|-----------------\n",
+      "    certifi-2020.11.8          |   py37h06a4308_0         148 KB\n",
+      "    ipython-7.19.0             |   py37hb070fc8_0         978 KB\n",
+      "    jupyter_core-4.7.0         |   py37h06a4308_0          68 KB\n",
+      "    numpy-1.19.2               |   py37h54aff64_0          22 KB\n",
+      "    numpy-base-1.19.2          |   py37hfa32c7d_0         4.1 MB\n",
+      "    pexpect-4.8.0              |     pyhd3eb1b0_3          53 KB\n",
+      "    pip-20.2.4                 |   py37h06a4308_0         1.7 MB\n",
+      "    ptyprocess-0.6.0           |     pyhd3eb1b0_2          20 KB\n",
+      "    pygments-2.7.2             |     pyhd3eb1b0_0         674 KB\n",
+      "    setuptools-50.3.1          |   py37h06a4308_1         711 KB\n",
+      "    six-1.15.0                 |   py37h06a4308_0          27 KB\n",
+      "    wheel-0.35.1               |     pyhd3eb1b0_0          38 KB\n",
+      "    ------------------------------------------------------------\n",
+      "                                           Total:         8.5 MB\n",
+      "\n",
+      "The following NEW packages will be INSTALLED:\n",
+      "\n",
+      "  _libgcc_mutex      pkgs/main/linux-64::_libgcc_mutex-0.1-main\n",
+      "  backcall           pkgs/main/noarch::backcall-0.2.0-py_0\n",
+      "  blas               pkgs/main/linux-64::blas-1.0-mkl\n",
+      "  ca-certificates    pkgs/main/linux-64::ca-certificates-2020.10.14-0\n",
+      "  certifi            pkgs/main/linux-64::certifi-2020.11.8-py37h06a4308_0\n",
+      "  decorator          pkgs/main/noarch::decorator-4.4.2-py_0\n",
+      "  intel-openmp       pkgs/main/linux-64::intel-openmp-2020.2-254\n",
+      "  ipykernel          pkgs/main/linux-64::ipykernel-5.3.4-py37h5ca1d4c_0\n",
+      "  ipython            pkgs/main/linux-64::ipython-7.19.0-py37hb070fc8_0\n",
+      "  ipython_genutils   pkgs/main/linux-64::ipython_genutils-0.2.0-py37_0\n",
+      "  jedi               pkgs/main/linux-64::jedi-0.17.2-py37_0\n",
+      "  jupyter_client     pkgs/main/noarch::jupyter_client-6.1.7-py_0\n",
+      "  jupyter_core       pkgs/main/linux-64::jupyter_core-4.7.0-py37h06a4308_0\n",
+      "  ld_impl_linux-64   pkgs/main/linux-64::ld_impl_linux-64-2.33.1-h53a641e_7\n",
+      "  libedit            pkgs/main/linux-64::libedit-3.1.20191231-h14c3975_1\n",
+      "  libffi             pkgs/main/linux-64::libffi-3.3-he6710b0_2\n",
+      "  libgcc-ng          pkgs/main/linux-64::libgcc-ng-9.1.0-hdf63c60_0\n",
+      "  libsodium          pkgs/main/linux-64::libsodium-1.0.18-h7b6447c_0\n",
+      "  libstdcxx-ng       pkgs/main/linux-64::libstdcxx-ng-9.1.0-hdf63c60_0\n",
+      "  mkl                pkgs/main/linux-64::mkl-2020.2-256\n",
+      "  mkl-service        pkgs/main/linux-64::mkl-service-2.3.0-py37he904b0f_0\n",
+      "  mkl_fft            pkgs/main/linux-64::mkl_fft-1.2.0-py37h23d657b_0\n",
+      "  mkl_random         pkgs/main/linux-64::mkl_random-1.1.1-py37h0573a6f_0\n",
+      "  ncurses            pkgs/main/linux-64::ncurses-6.2-he6710b0_1\n",
+      "  numpy              pkgs/main/linux-64::numpy-1.19.2-py37h54aff64_0\n",
+      "  numpy-base         pkgs/main/linux-64::numpy-base-1.19.2-py37hfa32c7d_0\n",
+      "  openssl            pkgs/main/linux-64::openssl-1.1.1h-h7b6447c_0\n",
+      "  parso              pkgs/main/noarch::parso-0.7.0-py_0\n",
+      "  pexpect            pkgs/main/noarch::pexpect-4.8.0-pyhd3eb1b0_3\n",
+      "  pickleshare        pkgs/main/linux-64::pickleshare-0.7.5-py37_1001\n",
+      "  pip                pkgs/main/linux-64::pip-20.2.4-py37h06a4308_0\n",
+      "  prompt-toolkit     pkgs/main/noarch::prompt-toolkit-3.0.8-py_0\n",
+      "  ptyprocess         pkgs/main/noarch::ptyprocess-0.6.0-pyhd3eb1b0_2\n",
+      "  pygments           pkgs/main/noarch::pygments-2.7.2-pyhd3eb1b0_0\n",
+      "  python             pkgs/main/linux-64::python-3.7.9-h7579374_0\n",
+      "  python-dateutil    pkgs/main/noarch::python-dateutil-2.8.1-py_0\n",
+      "  pyzmq              pkgs/main/linux-64::pyzmq-19.0.2-py37he6710b0_1\n",
+      "  readline           pkgs/main/linux-64::readline-8.0-h7b6447c_0\n",
+      "  setuptools         pkgs/main/linux-64::setuptools-50.3.1-py37h06a4308_1\n",
+      "  six                pkgs/main/linux-64::six-1.15.0-py37h06a4308_0\n",
+      "  sqlite             pkgs/main/linux-64::sqlite-3.33.0-h62c20be_0\n",
+      "  tk                 pkgs/main/linux-64::tk-8.6.10-hbc83047_0\n",
+      "  tornado            pkgs/main/linux-64::tornado-6.0.4-py37h7b6447c_1\n",
+      "  traitlets          pkgs/main/noarch::traitlets-5.0.5-py_0\n",
+      "  wcwidth            pkgs/main/noarch::wcwidth-0.2.5-py_0\n",
+      "  wheel              pkgs/main/noarch::wheel-0.35.1-pyhd3eb1b0_0\n",
+      "  xz                 pkgs/main/linux-64::xz-5.2.5-h7b6447c_0\n",
+      "  zeromq             pkgs/main/linux-64::zeromq-4.3.3-he6710b0_3\n",
+      "  zlib               pkgs/main/linux-64::zlib-1.2.11-h7b6447c_3\n",
+      "\n",
+      "\n",
+      "\n",
+      "Downloading and Extracting Packages\n",
+      "numpy-1.19.2         | 22 KB     | ##################################### | 100% \n",
+      "pip-20.2.4           | 1.7 MB    | ##################################### | 100% \n",
+      "numpy-base-1.19.2    | 4.1 MB    | ##################################### | 100% \n",
+      "certifi-2020.11.8    | 148 KB    | ##################################### | 100% \n",
+      "wheel-0.35.1         | 38 KB     | ##################################### | 100% \n",
+      "ipython-7.19.0       | 978 KB    | ##################################### | 100% \n",
+      "pexpect-4.8.0        | 53 KB     | ##################################### | 100% \n",
+      "pygments-2.7.2       | 674 KB    | ##################################### | 100% \n",
+      "ptyprocess-0.6.0     | 20 KB     | ##################################### | 100% \n",
+      "jupyter_core-4.7.0   | 68 KB     | ##################################### | 100% \n",
+      "setuptools-50.3.1    | 711 KB    | ##################################### | 100% \n",
+      "six-1.15.0           | 27 KB     | ##################################### | 100% \n",
+      "Preparing transaction: done\n",
+      "Verifying transaction: done\n",
+      "Executing transaction: done\n",
+      "#\n",
+      "# To activate this environment, use\n",
+      "#\n",
+      "#     $ conda activate myenv\n",
+      "#\n",
+      "# To deactivate an active environment, use\n",
+      "#\n",
+      "#     $ conda deactivate\n",
+      "\n"
+     ]
+    }
+   ],
+   "source": [
+    "# Create a environment with conda\n",
+    "!conda create -y -n myenv python=3.7 numpy ipykernel"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "### Add the new environment to your active kernels\n",
+    "This way you can choose the kernel from the Jupyterlab launcher."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 4,
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Installed kernelspec MYENV in /jetfs/home/mblaschek/.local/share/jupyter/kernels/myenv\n"
+     ]
+    }
+   ],
+   "source": [
+    "!~/.conda/envs/myenv/bin/python -m ipykernel install --user --name MYENV --display-name \"Py3.7\""
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Available kernels:\n",
+      "  myenv      /jetfs/home/mblaschek/.local/share/jupyter/kernels/myenv\n",
+      "  python3    /jetfs/spack/opt/spack/linux-rhel8-skylake_avx512/gcc-8.3.1/miniconda3-4.8.2-3m7b6t2kgedyr3jnd2nasmgiq7wm27iv/share/jupyter/kernels/python3\n"
+     ]
+    }
+   ],
+   "source": [
+    "# List available Kernels\n",
+    "!jupyter kernelspec list"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "## Custom Environment Python Environment"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 6,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Setup a virtual Environment for your Python in the directoy: myfancyenv\n",
+    "!python -m venv myfancyenv "
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 7,
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "bin  include  lib  lib64  pyvenv.cfg\n"
+     ]
+    }
+   ],
+   "source": [
+    "# Creates a directory with new environment\n",
+    "!ls myfancyenv/"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 8,
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "\u001b[33mWARNING: You are using pip version 19.2.3, however version 20.2.4 is available.\n",
+      "You should consider upgrading via the 'pip install --upgrade pip' command.\u001b[0m\n"
+     ]
+    }
+   ],
+   "source": [
+    "# Install some package into that environment\n",
+    "# important is ipykernel to use it within jupyterlab/notebook\n",
+    "!./myfancyenv/bin/pip -q install numpy scipy pandas ipykernel"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 9,
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Installed kernelspec fancy in /jetfs/home/mblaschek/.local/share/jupyter/kernels/fancy\n"
+     ]
+    }
+   ],
+   "source": [
+    "# Allow this environment to be available on the LAUNCHERS (+) sign on the left\n",
+    "!./myfancyenv/bin/python -m ipykernel install --user --name fancy --display-name \"My Python\""
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "Wait a bit and the new python environment should be available on your launchers."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 10,
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Available kernels:\n",
+      "  fancy      /jetfs/home/mblaschek/.local/share/jupyter/kernels/fancy\n",
+      "  myenv      /jetfs/home/mblaschek/.local/share/jupyter/kernels/myenv\n",
+      "  python3    /jetfs/spack/opt/spack/linux-rhel8-skylake_avx512/gcc-8.3.1/miniconda3-4.8.2-3m7b6t2kgedyr3jnd2nasmgiq7wm27iv/share/jupyter/kernels/python3\n"
+     ]
+    }
+   ],
+   "source": [
+    "!jupyter kernelspec list"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "### Finished"
+   ]
+  }
+ ],
+ "metadata": {
+  "kernelspec": {
+   "display_name": "Miniconda3 (4.8.2)",
+   "language": "python",
+   "name": "python3"
+  },
+  "language_info": {
+   "codemirror_mode": {
+    "name": "ipython",
+    "version": 3
+   },
+   "file_extension": ".py",
+   "mimetype": "text/x-python",
+   "name": "python",
+   "nbconvert_exporter": "python",
+   "pygments_lexer": "ipython3",
+   "version": "3.8.1"
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 4
+}
-- 
GitLab