Conda command in the jupyterlab console

Good morning everyone,

When using conda activate myenv in the jupyterlab console (spawn through k8s jupyterhub), I have this error :

    CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
    To initialize your shell, run

        $ conda init <SHELL_NAME>

    Currently supported shells are:
      - bash
      - fish
      - tcsh
      - xonsh
      - zsh
      - powershell

    See 'conda init --help' for more information and options.

    IMPORTANT: You may need to close and restart your shell after running 'conda init'.

I tried to add this line in my config.yaml as advised in diverse others places.

    001_config: |
      c.NotebookApp.terminado_settings = { 'shell_command': ['bash'] }

But that makes no difference in the console.
Could you advised me on how to fix this problem please ?

More info after debugging:
It seems that .bashrc is not sourced. when doing source .bashrc in my console it works. How I can configurate it to be sourced automatically ?


Fixed by adding in my custom docker image :
echo source $HOME/.bashrc >> /etc/profile

However, it is more feel like a workaround instead of an actual fix. If someone has a better solution, I am still interested.

If you are already in a login shell environment and it’s not getting sourced, you might want to add source ~/.bashrc to ~/.bash_profile. I still get confused about which one is run when.

To get a proper shell environment, I think it’s a good idea to launch a ‘login shell’, which does things like source bashrc, profiles, etc.

For me, I often set the ENTRYPOINT to ensure this happens for Jupyter user images:

#!/bin/bash -l
# the -l means login shell, which sources profiles, etc.
# extra env setup could go here
# this bit means launch whatever command I was given
# which probably starts `jupyterhub-singleuser` or something
exec "$@"
1 Like

Thanks for the tip, i will test it.