<jupyter_start><jupyter_text>Adding environments in Jupyter HubTo run the cells in this Jupyter Notebook, just click on the cell you want to run and press **shift-enter**.  Context for this notebookIf you connected to VCDAT via NERSC, ACME1, Crunchy or a local area network, your *JupyterLab* experience is actually a *JupyterHub* experience though the two interfaces look almost the same. (JupyterHub is for multi-user situations, JupyterLab is for single-user situations like running from your own computer.) The environments available to you by default via JupyterHub are more limited than the environments you can set up on your own computer. This notebook shows you how to add an environment via JupyterHub since you might want to use an environment that is not automatically provided. If you launched JupyterLab from your own computer, JupyterLab can see and use any environments you've created on your computer. If you need a different environment than what already exists, just create that environment in a command line window, relaunch JupyterLab and those environments should be available. (Note: you can launch JupyterLab using one enviornment, like jupyter-vcdat which has the code to run JupyterLab, and then use a different environment within JupyterLab as the notebook below describes.)  Adding and Using Conda EnvironmentsYou have access to conda as a software management tool.**NOTE: Anything installed in the [base] conda environment will not persist between sessions.**As an example, let's create a new environment called "test" based on python 3.6.**NOTE: For a new conda environment to be available in a Jupyter Lab you must install the "ipykernel" package.**<jupyter_code>!conda create -n test -c conda-forge -y python=3.6 ipykernel<jupyter_output>Collecting package metadata: done
Solving environment: done

## Package Plan ##

  environment location: /Users/davis278/miniconda3/envs/test

  added / updated specs:
    - ipykernel
    - python=3.6


The following NEW packages will be INSTALLED:

  appnope            conda-forge/osx-64::appnope-0.1.0-py36_1000
  backcall           conda-forge/noarch::backcall-0.1.0-py_0
  ca-certificates    conda-forge/osx-64::ca-certificates-2019.3.9-hecc5488_0
  certifi            conda-forge/osx-64::certifi-2019.3.9-py36_0
  decorator          conda-forge/noarch::decorator-4.4.0-py_0
  ipykernel          conda-forge/osx-64::ipykernel-5.1.1-py36h24bf2e0_0
  ipython            conda-forge/osx-64::ipython-7.5.0-py36h24bf2e0_0
  ipython_genutils   conda-forge/noarch::ipython_genutils-0.2.0-py_1
  jedi               conda-forge/osx-64::jedi-0.13.3-py36_0
  jupyter_client     conda-forge/noarch::jupyter_client-5.2.4-py_3
  jupyter_core       conda-forge/noarch::jupyter_core-4.4.0-py_0
  libcxx         [...]<jupyter_text>**NOTE: You will need to activate the conda environment through a terminal instance.**To use the new conda environment in a Jupyter Notebook you have two options:1. Choose the Hub menu at the top of this page (assuming you have connected to a multi-user computer like ACME1, Crunchy or NERSC's Cori computer - the single-user JupyterLab interface does not have the "Hub" menu) and click "Control Panel". On the new page you'll need to click "Stop My Server" and then "Start My Server" OR,2. Run the following python script to load the new environment. (This line of code works regardless of whether you are accessing VCDAT via JupyterHub or JupyterLab, i.e. it will work on your computer as well as on multi-user computers.)<jupyter_code>!python -c "from nb_conda_kernels import CondaKernelSpecManager; m = CondaKernelSpecManager(); m.find_kernel_specs()"<jupyter_output><empty_output><jupyter_text>In the upper right-hand corner, you can click the button similar to the one shown below to select the new "test" kernel. ![kernel](https://raw.githubusercontent.com/esgf-nimbus/getting_started/master/img/kernel.png) Now select the "conda env:test" kernel. ![selection](https://raw.githubusercontent.com/esgf-nimbus/getting_started/master/img/kernel_selection.png) Using the Jupyter Lab terminal you can activate the conda environment and install additional software.```bashconda activate testconda install -c conda-forge vcs```You can also do this from within a Notebook.**NOTE: This will run everytime the cell runs.**<jupyter_code>!conda install -n test -c cdat/label/v81 -c conda-forge -y vcs<jupyter_output>Collecting package metadata: done
Solving environment: done

## Package Plan ##

  environment location: /Users/davis278/miniconda3/envs/test

  added / updated specs:
    - vcs


The following NEW packages will be INSTALLED:

  asn1crypto         conda-forge/osx-64::asn1crypto-0.24.0-py36_1003
  attrs              conda-forge/noarch::attrs-19.1.0-py_0
  blas               conda-forge/osx-64::blas-1.1-openblas
  bzip2              conda-forge/osx-64::bzip2-1.0.6-h1de35cc_1002
  cdat_info          cdat/label/v81/noarch::cdat_info-8.1.1-py_0
  cdms2              cdat/label/v81/osx-64::cdms2-3.1.2-py36hcfef303_7
  cdtime             conda-forge/osx-64::cdtime-3.1.2-py36hcfef303_1
  cdutil             cdat/label/v81/noarch::cdutil-8.1-py_1
  cffi               conda-forge/osx-64::cffi-1.12.3-py36hccf1714_0
  chardet            conda-forge/osx-64::chardet-3.0.4-py36_1003
  cryptography       conda-forge/osx-64::cryptography-2.7-py36h212c5bf_0
  curl               conda-forge/osx-64::curl-7.[...]<jupyter_text>As a comparision for the next step, let's list all the environments available using the following command. We can see that the "test" environment exists.<jupyter_code>!conda env list<jupyter_output># conda environments:
#
base                     /Users/davis278/miniconda3
cdat81                   /Users/davis278/miniconda3/envs/cdat81
cdat_nightly             /Users/davis278/miniconda3/envs/cdat_nightly
e3sm                     /Users/davis278/miniconda3/envs/e3sm
globus                   /Users/davis278/miniconda3/envs/globus
jekyll                   /Users/davis278/miniconda3/envs/jekyll
jupyter-vcdat            /Users/davis278/miniconda3/envs/jupyter-vcdat
rtd                      /Users/davis278/miniconda3/envs/rtd
test                  *  /Users/davis278/miniconda3/envs/test
vcdat                    /Users/davis278/miniconda3/envs/vcdat<jupyter_text>Finally you can remove the environment but first **if you activated the environment in this notebook you must choose another environment**, e.g. "root", by changing the kernel either as you did before using the button in the upper right-hand corner or by clicking on the "Kernel" menu / tab in the upper left and choosing "Change Kernel".After you have changed the kernel to something other than "test" you can delete the "test" environment with the following line of code.<jupyter_code>!conda env remove -n test -y<jupyter_output>Remove all packages in environment /Users/davis278/miniconda3/envs/test:<jupyter_text>To verify that the "test" environment was removed, run the following bash command again. (The ! is needed for all but the most common bash commands to run within a Jupyter notebook).<jupyter_code>!conda env list<jupyter_output># conda environments:
#
base                     /Users/davis278/miniconda3
cdat81                   /Users/davis278/miniconda3/envs/cdat81
cdat_nightly             /Users/davis278/miniconda3/envs/cdat_nightly
e3sm                     /Users/davis278/miniconda3/envs/e3sm
globus                   /Users/davis278/miniconda3/envs/globus
jekyll                   /Users/davis278/miniconda3/envs/jekyll
jupyter-vcdat         *  /Users/davis278/miniconda3/envs/jupyter-vcdat
rtd                      /Users/davis278/miniconda3/envs/rtd
vcdat                    /Users/davis278/miniconda3/envs/vcdat
{'fraction_non_alphanumeric': 0.07949249093733816, 'fraction_numerical': 0.04039357845675816, 'mean_word_length': 3.364406779661017, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '271177', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 2693, 'n_tokens_neox': 2489, 'n_words': 744, 'path': 'docs/notebooks/add_envs_in_hub.ipynb', 'repo_name': 'CDAT/jupyter-vcdat', 'size': '7724'}