Python kernel that picks up environment from directory

How to best configure different kernels with different python virtualenvs (or similar) in different projects and directories?

Instead of installing a separate kernel per virtualenv, I want to install just one versatile “meta-kernel” or “kernel trampoline” that launches the relevant python kernel for the directory that a notebook belongs to. It is conceptually simpler, and it also should work a lot better when working in a team and sharing code.

I’m working on a prototype for that, that will use Rye to manage python versions, dependencies and virtualenv per jupyter(lab) project.

I was inspired by poetry-kernel which is based on the same concept - it’s the same idea, except they use Poetry as the manager. Do you all know other similar projects like this? Any more established ones?

My (extremely short) code is here: GitHub - bluss/ryeish-kernel: Python Jupyter kernel using Rye for reproducible notebooks and it’s a usable proof of concept. (It’s using Rye which itself is up and coming and not really ready.) There’s a directory called example there in the source code, that maybe can help explain how you would use it.


Does anybody know about other project that already do something like this? Like, activate a local venv per path and use kernel & dependencies from that path? Or similar. I did expect it to already exist. Maybe in a version that’s quite general and can maybe autodetect some common ways these environments are named.

That’s cool! Not directly what you are asking for but JupyterLab Desktop remembers environment by writing it’s name into a file in .jupyter folder locally. This is however used on per server not per kernel basis.

I wonder if an env manager-agnostic solution would have its place as a (semi-?)official tool in Jupyter ecosystem. By that I mean something that would recognise .python-version from pyenv, support conda/mamba/etc as well as poetry, Rye and whatever comes next.

1 Like

Hi, I am interested in trying out rye, and would need a tool similar to what poetry-kernel does for poetry. So I found ryeish-kernel! Seems like a nice tool but it wasn’t clear to me from the readme how to use it? Could yo add some (brief) instructions to it? Thanks a lot!