Conda for teaching: Difference between revisions

From HPCwiki
Jump to navigation Jump to search
(Created page with "You are going to give a teaching course, and you need a specific code environment. == Setup == First - find a good location that everyone can read (and not write). I'd sugges...")
 
Line 61: Line 61:


In order for students to be able to use this environment in jupyter, they will need a kernel definition.
In order for students to be able to use this environment in jupyter, they will need a kernel definition.
{
"env": {
  "PATH":
"/cm/shared/apps/SHARED/my_conda_env/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"
},
"language": "python",
"argv": [
  "/cm/shared/apps/SHARED/my_conda_env/bin/python",
  "-m",
  "ipykernel",
  "-f",
  "{connection_file}"
],
"display_name": "my_conda_env"
}

Revision as of 09:40, 27 May 2020

You are going to give a teaching course, and you need a specific code environment.

Setup

First - find a good location that everyone can read (and not write). I'd suggest somewhere under /cm/shared/apps/SHARED/ as a starting point - this allows everyone to access this location. It's important not to put anything secret there - it's a public resource, so please bear that in mind.

Next - create a folder for your environment:

<source lang='bash'> mkdir /cm/shared/apps/SHARED/my_conda_env chmod +r /cm/shared/apps/SHARED/my_conda_env </source> You may want to manipulate the permissions for this folder if someone is going to set this up with you. Consider the commands in Shared Folders.

Then, install Anaconda into it:

<source lang='bash'> wget https://repo.anaconda.com/archive/Anaconda3-YEAR.MONTH-Linux-x86_64.sh ./Anaconda3-YEAR.MONTH-Linux-x86_64.sh -s -b -p /cm/shared/apps/SHARED/my_conda_env </source>

Now you have a working conda environment in this folder. You can manipulate this here by running /cm/shared/apps/SHARED/my_conda_env/bin/conda , or, I would recommend creating a modulefile so that you can use it as default.

Create the following example modulefile in a matching /cm/shared/modulefiles/SHARED/my_conda_env :

<source lang='bash'>

  1. %Module -*- tcl -*-
    1. conda environment modulefile

set loadedmodules [split $::env(LOADEDMODULES) ":"] set modulepath [split $ModulesCurrentModulefile "/"] set envpath [lrange $modulepath 4 end]

set root /cm/shared/apps/[join $envpath "/"]

proc ModulesHelp { } {

       global version
       puts stderr "\tThis module provides the conda environment at $envpath"

}


if { [module-info mode] != "whatis" } {

       puts stderr "[module-info mode] environent $envpath ."

}

module-whatis "Provides environment $envpath"


prepend-path PATH $root/bin prepend-path LD_LIBRARY_PATH $root/lib prepend-path LIBRARY_PATH $root/lib prepend-path CPATH $root/include prepend-path MANPATH $root/share/man </source>

This will allow you to `module load SHARED/my_conda_env` and thus have `conda` pathed to the currently active environment.

Jupyter Kernel

In order for students to be able to use this environment in jupyter, they will need a kernel definition.


{

"env": {
  "PATH":

"/cm/shared/apps/SHARED/my_conda_env/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin" },

"language": "python",
"argv": [
 "/cm/shared/apps/SHARED/my_conda_env/bin/python",
 "-m",
 "ipykernel",
 "-f",
 "{connection_file}"
],
"display_name": "my_conda_env"

}