# How to set up one or more per user virtual environments in jupyterhub

**URL:** <https://discourse.jupyter.org/t/how-to-set-up-one-or-more-per-user-virtual-environments-in-jupyterhub/19378>\
**Category:** JupyterHub\
**Tags:** how-to\
**Created:** [May 13, 2023, 6:29pm UTC](https://discourse.jupyter.org/t/how-to-set-up-one-or-more-per-user-virtual-environments-in-jupyterhub/19378 "2023-05-13T18:29:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gback](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/gback/32/9457_2.png) [@gback](https://discourse.jupyter.org/u/gback)\
**Post date:** [May 13, 2023, 6:29pm UTC](https://discourse.jupyter.org/t/how-to-set-up-one-or-more-per-user-virtual-environments-in-jupyterhub/19378/1 "2023-05-13T18:29:56Z")

</div>

I set up jupyterhub+lab following the instructions [posted here](https://github.com/jupyterhub/jupyterhub-the-hard-way/blob/35ddfb49ad81771551c6549696ccec960564d5e4/docs/installation-guide-hard.md), except for part 2 which would have involved conda. I’m much more familiar with pip and after bad experiences in the past, I’d like to avoid conda if possible.

When I log in as a user and open a shell I seem to be in the venv in which jupyterlab was set up. When I open a notebook the same seems to be the case.

Is it possible to set it up such that each user can create their own virtual (pip) environment or environments? If so, is there a guide to how to do so?

The only information I’ve found so far appears to be [`c.Spawner.cmd`](https://jupyterhub.readthedocs.io/en/stable/reference/api/spawner.html#jupyterhub.spawner.Spawner.cmd); which states that: _This is usually set if you want to start the single-user server in a different python environment (with virtualenv/conda) than JupyterHub itself._ but there are no examples.

Where would I find pointers/documentation/working examples for such a setup?  
In Jupyterlab lingo, is a Python instance running inside a virtual env the same as a “kernel?”

---

<div class="post-metadata">

**Author:** ![gback](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/gback/32/9457_2.png) [@gback](https://discourse.jupyter.org/u/gback)\
**Post date:** [May 15, 2023, 11:37am UTC](https://discourse.jupyter.org/t/how-to-set-up-one-or-more-per-user-virtual-environments-in-jupyterhub/19378/2 "2023-05-15T11:37:14Z")

</div>

Here’s what I tried with partial success.

- create a virtual environment as usual.
- install `ipykernel` in it and all other packages you want/need.
- activate it. This should give you an executable `ipython` in your path
- run `ipython kernel install --prefix /tmp`
- this will give you a hierarchy `/tmp/share/jupyter/kernels/python3` - that directory contains a `kernel.json` file

Then, leave the virtual environment and activate the virtual environment jupyterhub lives in.

- then run `jupyter kernelspec install --user /tmp/share/jupyter/kernels/python3` - this will copy the configuration into `~/.local/share/jupyter/kernels/python3` from where, it appears, Jupyterhub will read it.

This seems to work for Notebooks - however, when I open a shell, I’m still in the Jupyterhub environment.

---

<div class="post-metadata">

**Author:** ![stebo85](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/stebo85/32/7864_2.png) [@stebo85](https://discourse.jupyter.org/u/stebo85)\
**Post date:** [May 25, 2023, 3:39am UTC](https://discourse.jupyter.org/t/how-to-set-up-one-or-more-per-user-virtual-environments-in-jupyterhub/19378/3 "2023-05-25T03:39:30Z")

</div>

It seems that you don’t want to use conda, so my solution might not work for you. But using conda and the package nb\_conda\_kernels works nicely.

You can then create additional conda environments with

```auto
conda create -n myenv ipykernel

```

and it shows up on the launcher page of JupyterHub.
