# Multiple Conda Environments

**URL:** <https://discourse.jupyter.org/t/multiple-conda-environments/22530>\
**Category:** The Littlest JupyterHub\
**Tags:** help-wanted\
**Created:** [November 21, 2023, 11:27pm UTC](https://discourse.jupyter.org/t/multiple-conda-environments/22530 "2023-11-21T23:27:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mwrowe](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@mwrowe](https://discourse.jupyter.org/u/mwrowe)\
**Post date:** [November 21, 2023, 11:27pm UTC](https://discourse.jupyter.org/t/multiple-conda-environments/22530/1 "2023-11-21T23:27:14Z")

</div>

I am running a TLJH server on AWS. Some of the Jupyter notebooks I am hosting have very different requirements. Rather than adding all of those (potentially conflicting) requirements into the default base environment at `/opt/tljh/user`, I would like to make multiple environments available, and am hoping users could pick the appropriate environment from the kernel selector within each notebook (like you can do if running notebooks from VS Code).

Is this possible?

If so, how do I recreate the initial base environment used by TLJH? The [“What does the installer do?” page](https://tljh.jupyter.org/en/latest/topic/installer-actions.html#user-environment) says it installs a mambaforge environment, but doesn’t give any details beyond that.

Thanks in advance for your help!

---

<div class="post-metadata">

**Author:** ![minrk](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/minrk/32/13_2.png) [@minrk](https://discourse.jupyter.org/u/minrk)\
**Post date:** [November 24, 2023, 10:25am UTC](https://discourse.jupyter.org/t/multiple-conda-environments/22530/2 "2023-11-24T10:25:02Z")

</div>

> [@mwrowe](#):
>
> says it installs a mambaforge environment, but doesn’t give any details beyond that.

The main thing is that the user environment at `/opt/tljh/user` is a conda env, so you can use `sudo /opt/tljh/user/bin/conda` to perform operations that will be shared by users.

> Is this possible?

Yes, indeed, you can do this. Once things are set up, you can create environments, e.g.

(e.g. creating new shared envs):

```bash
sudo /opt/tljh/user/bin/conda create -n env-name python=3.10 ipykernel [more packages]

```

To make it a kernel, you need to make sure the `ipykernel` package is in the env (assuming you are making envs for Python kernels, otherwise you need whatever kernel package you are using).

The next step is to make the kernels in each env _available_ to the `user` env.

You have two options, generally:

1. manually, explicitly, for each env:

2. use something like [nb\_conda\_kernels](https://github.com/Anaconda-Platform/nb_conda_kernels) to _automatically_ locate any conda environments and create kernelspecs for them, though that is largely unmaintained, and seems to have some compatibility issues at this point.

This process is the same for Python virtualenvs or any other environment installation of your choice. The main thing if you are creating a _shared_ environment is the fileystem permissions - users should have read-execute permissions on the env (this should be the default if you create it with `sudo conda create`, but may not be for every possible way to create an env).

---

<div class="post-metadata">

**Author:** ![mwrowe](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@mwrowe](https://discourse.jupyter.org/u/mwrowe)\
**Post date:** [November 27, 2023, 5:22pm UTC](https://discourse.jupyter.org/t/multiple-conda-environments/22530/3 "2023-11-27T17:22:32Z")

</div>

@minrk Thanks for the detailed solution-- I’ll definitely give it a try! I had gotten as far as creating another environment, but couldn’t figure out how to expose it. Thanks for the tips.

I especially like the option to use other venv’s besides conda-- not a fan. We have custom python modules we install from an internal PyPI, which is not supported by conda. I don’t like having to use a mixed conda/pip installation; seems potentially problematic having two different packages managing dependencies. I prefer to use poetry or pipenv. Hopefully this will solve all my problems! ;^)

---

<div class="post-metadata">

**Author:** ![minrk](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/minrk/32/13_2.png) [@minrk](https://discourse.jupyter.org/u/minrk)\
**Post date:** [November 28, 2023, 9:43am UTC](https://discourse.jupyter.org/t/multiple-conda-environments/22530/4 "2023-11-28T09:43:25Z")

</div>

Yes, you can register any Python installation (with ipykernel installed) as a kernel. The same goes for R, Julia, etc. We often use conda just to get Python itself started, then pip for python packages. That works just fine, but if you have a base Python via other means, there’s no reason you can’t use that as well. It doesn’t need to have any relationship with the _user_ environment, which is where `jupyter-server` runs, other than placing the kernelspec (which is a .json file and a logo) in that prefix (or system-wide in /usr/local).

---

<div class="post-metadata">

**Author:** ![mwrowe](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@mwrowe](https://discourse.jupyter.org/u/mwrowe)\
**Post date:** [June 21, 2024, 12:46am UTC](https://discourse.jupyter.org/t/multiple-conda-environments/22530/5 "2024-06-21T00:46:23Z")

</div>

Hi @minrk – I finally got around to setting this up using your instructions. I had originally planned to install pyenv and then create poetry environments on top of that. But I realized that it is possible to use poetry with conda, which is much simpler since it is already set up. [This guide](https://medium.com/@silvinohenriqueteixeiramalta/conda-and-poetry-a-harmonious-fusion-8116895b6380) was useful.

Anyway, it all seems to be working and I can now finally mirror my TLJH environments in my dev environment for testing, as well as have different environments for different notebooks I am distributing! Thanks again for all your help!
