QIIME2 and Jupyterhub

Hello,

Awhile back, I wrote a post about getting QIIME2 up and running with jupyterhub. I have never been able to get it running “out-of-the-box”. The issue that I am running into is that the PATH variable used by the single user notebooks is not the path that jupyter hub uses and so when a call to an exernal package is made the package will not be found.

I realize this is not an issue with QIIME, but rather with jupyterhub, however given the potential use of jupyterhub for classes or workshops (or companies) I wanted to post this in case anyone else has run into a similar issue or has found a solution.

One workaround I have found is to update the path from inside of the notebook where QIIME is being run:

import os
os.environ['PATH'] = '/home/jovyan/my-conda-envs/qiime2-2018.8/bin:' + os.environ['PATH']

I also posted an issue about this on jupyterhub

Hey @John_Chase,

That’s a good trick, although I still think the right approach is to create a custom spawner which generates new kernels for all of the user’s environments. Then the $PATH var can be set appropriately. (This can happen more or less dynamically).

1 Like

create a custom spawner which generates new kernels for all of the user’s environments

This is actually what happens now. I don't think it is possible to point to the correct path unless the notebook is started from within the conda environment.

I remember discovering that you can set the "env" of a kernel.

For example, on our mostly disused jupyterhub, we use the following as a kernel template:

KERNEL_TEMPLATE = """{
 "argv": ["%s", "-m", "IPython.kernel", 
          "-f", "{connection_file}"],
 "display_name": "%s",
 "language": "python",
 "env": {"PATH": "%s"}
}
"""

At the end, we set PATH inside the "env". This means that every launched kernel will have that PATH pre-populated from the conda env :slight_smile:

Detailed docs for the kernelspec can be found here:
https://jupyter-client.readthedocs.io/en/latest/kernels.html#kernelspecs

2 Likes

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.