# Loading python venvs (adding environment\_kernels to JupyterHub)

**URL:** <https://discourse.jupyter.org/t/loading-python-venvs-adding-environment-kernels-to-jupyterhub/1803>\
**Category:** JupyterHub\
**Created:** [August 1, 2019, 10:39am UTC](https://discourse.jupyter.org/t/loading-python-venvs-adding-environment-kernels-to-jupyterhub/1803 "2019-08-01T10:39:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pelacables](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/pelacables/32/970_2.png) [@pelacables](https://discourse.jupyter.org/u/pelacables)\
**Post date:** [August 1, 2019, 10:39am UTC](https://discourse.jupyter.org/t/loading-python-venvs-adding-environment-kernels-to-jupyterhub/1803/1 "2019-08-01T10:39:24Z")

</div>

Hello all,

I’d like to allow jupyterhub users to load kernels from their own python virtualenvs. Mainly I’d like to let them install their packages in a virtualenv and the load it in the hub.

I followed some instructions that, basically, say that, after activating the python virtual env, one has to install the ipykernel and then add the venv to jupyter:

```bash
(venv) $ python -m pip install --user ipykernel
(venv) $ python -m ipykernel install --user --name=myenv

```

(someone uses the ipython instead of ipykernel to make the kernel available in jupyter, not sure what teh difference is between using ipykernel and ipython)

With the above commands I can later see my new kernel in the hub. So far so good.

The problem comes when one inspect the environment in the kernel: the PATH variable does not include the bin directory from the python venv. This is something someonbe already commented here: [https://github.com/jupyterhub/jupyterhub/issues/430#issuecomment-184978527](https://github.com/jupyterhub/jupyterhub/issues/430#issuecomment-184978527)

Again, I’m not sure if the reason is that some variables are passed to the spawner in the conf file:

```bash
c.Spawner.env_keep = [
'PATH',
'PYTHONPATH',
'LD_LIBRARY_PATH',
'LIBRARY_PATH',
'VIRTUAL_ENV',
'LANG',
'LC_ALL',
'HTTP_PROXY',
'HTTPS_PROXY',
'NO_PROXY',
]

```

In my case I need to keep PATH cause python itself is not installed in a default location.

According to the above link, the solution seems to be [https://github.com/Cadair/jupyter\_environment\_kernels](https://github.com/Cadair/jupyter_environment_kernels) : “A Jupyter plugin to enable the automatic detection of environments as kernels.”.

So, after insatlling the package environment\_kernels with pip I’ve added at the end of my jupyterhub\_config.py the line:

```bash
c.NotebookApp.kernel_spec_manager_class = 'environment_kernels.EnvironmentKernelSpecManager'

```

and then restarted jupyterhub.  
I’ve also installed my python venv in ~/.virtualenvs (as this is supposed to be the default directory where virtual\_envs packages searches for custom virtual\_envs), but the venvs does not show up in jupyterhub.

I know this question could be asked to the jupyter\_environment developer but I’m wonering if any of you alredy solved the virtual\_env PATH issue in jupyterhub by using jupyter\_environments, if yes how you did enable it, or using any other method to load the python virtual env.

TIA,  
Arnau

---

<div class="post-metadata">

**Author:** ![agutierr](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/agutierr/32/4124_2.png) [@agutierr](https://discourse.jupyter.org/u/agutierr)\
**Post date:** [April 7, 2021, 5:08pm UTC](https://discourse.jupyter.org/t/loading-python-venvs-adding-environment-kernels-to-jupyterhub/1803/2 "2021-04-07T17:08:23Z")

</div>

Hi there! I am on the same situation: creating virtual environments doesnt include the PATH env variable. The only way to fix this is editing kernel.json and include ENV with a literal to the PATH including the virtual environment… Is this the expected behaviour?
