iot-salzburg / gpu-jupyter

GPU-Jupyter: Leverage the flexibility of Jupyterlab through the power of your NVIDIA GPU to run your code from Tensorflow and Pytorch in collaborative notebooks on the GPU.
Apache License 2.0
698 stars 231 forks source link

Unable to change conda environment in kernel #121

Closed iguy0 closed 5 months ago

iguy0 commented 11 months ago

Hi,

I'm trying to add/change the conda/python environment and i'm unable to do so.

Steps to reproduce:

docker run --gpus all -d -it -p 8848:8888 -v /home/USER:/home/jovyan/work -e GRANT_SUDO=yes -e JUPYTER_ENABLE_LAB=yes --user root cschranz/gpu-jupyter:v1.5_cuda-11.6_ubuntu-20.04_python-only

Log into JupyterLab and add a different kernel/conda environment using the terminal

mkdir /home/jovyan/envs conda init bash exec $SHELL conda create -p /home/jovyan/envs/python3.11 python=3.11 conda activate /home/jovyan/envs/python3.11 pip install --user ipykernel python -m ipykernel install --user --name=python3.11 conda deactivate

at this point the kernel is available, but selecting the kernel gives me this

2023-10-18 21_25_53-Untitled ipynb - JupyterLab and 60 more pages - Profile 1 - Microsoft​ Edge

Installing packages via pip and conda end up under /opt/conda when importing them uses the 3.11 environment, and gives a ImportError error. How to fix this ?

iguy0 commented 11 months ago

I got it going. The solution and additional useful commands are below:

Create environment paths and init conda - this is executed from Terminal in Jupyterlab

mkdir /home/jovyan/envs conda init bash exec $SHELL

Install in conda base environment

conda install nb_conda_kernels # https://github.com/Anaconda-Platform/nb_conda_kernels

Install new Environment and kernel

conda create -p /home/jovyan/envs/python3.11 python=3.11.6 conda activate /home/jovyan/envs/python3.11 conda install ipykernel sudo ipython kernel install --name=python3.11 --display-name "Python 3.11 (Darts)" conda deactivate

Restart container to recognize new kernel

Remove kernel

jupyter kernelspec list jupyter kernelspec uninstall unwanted-kernel

iguy0 commented 11 months ago

Not a solution for the original issue but allows me to create additional environments/kernels

benz0li commented 9 months ago

@iguy0 See https://github.com/jupyter/docker-stacks/pull/2050.

FYI @mathematicalmichael

ChristophSchranz commented 5 months ago

Closing as there were no contributions for a while and it seems there is a workaround.