diff --git a/Programming/anaconda/README.md b/Programming/anaconda/README.md index 1fae725..d845b00 100644 --- a/Programming/anaconda/README.md +++ b/Programming/anaconda/README.md @@ -75,3 +75,35 @@ This works if the python package has a correct setup.py build cd /opt/psi/Programming/anaconda/2019.07/xxxx/mypackage pip install . ``` +## Building for use with jupyter + + Jupyter can discover conda environments if the environment contains the **nb_conda_kernels** package. + +Regrettably the environment activation by this package does not run through the full process as compared to the command line functions. The activation scripts that can be placed in an environment do not get executed (q.v. my bug report https://github.com/Anaconda-Platform/nb_conda_kernels/issues/145). + +In order to fix this, we must use a workaround which involves modifying the kernel spec configuration file of the environment to wrap the call to the python kernel like in this example for `.../envs/mpi-test/share/jupyter/kernels/python3/kernel.json`: + ``` + { + "argv": [ + "/opt/psi/Programming/anaconda/2019.07/admintools/kernelwrapper.sh", + "mpi-test", + "/opt/psi/Programming/anaconda/2019.07/conda/envs/mpi-test/bin/python", + "-m", + "ipykernel_launcher", + "-f", + "{connection_file}" + ], + "display_name": "Python 3", + "language": "python" + } + ``` + +In order to modify an environment easily I wrote a tool found in the `admintools` of this buildblock which you can use as follows: + + ``` + files/admintools/install-kernelwrapper.py -v /opt/psi/Programming/anaconda/2019.07/conda/envs/hep_root + ``` + + + + diff --git a/Programming/anaconda/files/admintools/kernelwrapper.sh b/Programming/anaconda/files/admintools/kernelwrapper.sh index 24268dd..44f391e 100755 --- a/Programming/anaconda/files/admintools/kernelwrapper.sh +++ b/Programming/anaconda/files/admintools/kernelwrapper.sh @@ -1,4 +1,13 @@ #!/bin/bash +# kernelwrapper.sh +# This wrapper is needed to correctly have jupyter activate conda evnironments +# including the running of the $ENV/etc/conda/activate.d hooks +# q.v. https://github.com/Anaconda-Platform/nb_conda_kernels/issues/145 +# +# This script must be called from the config located in an environment +# $ENV/share/jupyter/kernels/python3/kernel.jsonshare/jupyter/kernels/python3/kernel.json + +# 2019 - Derek Feichtinger dbgecho() { DBGLOG=/tmp/kernelwrapper-${USER}.log if [[ $DEBUG_JUPYTER_WRAPPER == 1 ]]; then