DEV Community

Cover image for Monitor  for any new conda env and add them as Jupyter kernels
Mostafa Gazar
Mostafa Gazar

Posted on

2

Monitor for any new conda env and add them as Jupyter kernels

Here is a little script that monitors the conda envs directory on linux and adds a kernel in Jupyter for each new env.

Alternatively you probably should use nb_conda_kernels instead.


#!/bin/bash

# Inspired by: https://unix.stackexchange.com/a/323919
# man page: https://linux.die.net/man/1/inotifywait
inotifywait -m /opt/conda/envs -e create -e moved_to |
    while read path action file; do
      if [[ "$file" == .* ]]; then # Does start with .
        echo "$file ignored"
      else
        # Wait for the env to get created
        echo "Waiting for $path$file/bin/python ..."
        while [ ! -f "$path$file/bin/python" ]; do sleep 1; done

        # Add the new conda env
        echo "Add $file kernel"
        source activate "$file" && \
        pip install --quiet ipykernel && \
        python -m ipykernel install --user --name "$file"
      fi
    done
Enter fullscreen mode Exit fullscreen mode

If you found this helpful spread the word.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please show some love ❤️ or share a kind word in the comments if you found this useful!

Got it!