0

My newly setup conda fails when I try to activate an existing environment inside tmux. Apparently it finds the conda binary but cannot run the command. Inside bash it works as expected.

Steps:

  1. Open bash

  2. Check that conda activate works in bash

  3. Open tmux

  4. Run conda activate in tmux, output below

    xxx@xxx:~$ conda activate 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'.

matt3o
  • 123

1 Answers1

0

I found the solution in this question.

The problem is I'm running tmux on a server with an interactive login shell, for details see .bashrc vs .bash_profile. Bash in this case only opens .bash_profile. So this means there are two solutions to the problem:

  1. Import .bashrc in .bash_profile, e.g. by adding

     if [ -f ~/.bashrc ]; then
         . ~/.bashrc
     fi
    
  2. Moving the conda init code block from .bashrc to .bash_profile

Edit: Updated with the comment of Kusalananda, thanks for the explanations.

matt3o
  • 123
  • 1
    No, tmux does not use .bashrc for initialisation, it starts a bash shell, and that shell reads .bashrc upon startup. The reason you .bashrc file isn't parsed might be that you either 1) don't use bash, or 2) (more likely) you use macOS and your .bash_profile file does not source .bashrc. Note: tmux does not care about your shell, and never has. To tmux, your shell is just some application that it starts when you haven't told it to do anything else. – Kusalananda Apr 03 '23 at 15:24
  • Good to know. Feel free to add a source or correct my comment directly, I only know about the problem, nothing about tmux. Also nope that is an Ubuntu server, so your comment is incorrect there. I can add the details to the question if necessary but this does not only happen on MacOs. Also default shell is bash and bash also starts, so I tested that as well – matt3o Apr 04 '23 at 17:36
  • The second part is correct though - .bash_profile does not include .bashrc, so that would surely be another working solution – matt3o Apr 04 '23 at 17:44
  • 1
    The first part could well be correct if tmux starts a login shell. A bash login shell would parse .bash_profile but not .bashrc unless it is explicitly sourced from .bash_profile (which it often is). In any case, tmux does not use .bashrc nor .bash_profile. It does not care. It is the shell that uses either or both of these depending on its configuration on your OS, whatever OS you use. – Kusalananda Apr 04 '23 at 18:44
  • Thanks for the explanation, I updated my answer including a source and adding the second solution – matt3o Apr 05 '23 at 06:58