8

Ok, so I am in my anaconda environment and I ran which python. I get

/home/comp/anaconda3/envs/env1/bin/python

Now if I start tmux, then run source activate env1, then which python, I get

/home/comp/anaconda3/bin/python

even though I do have my environment activated. How can I make anaconda see the same path inside tmux ?

12

The solution seems to be to deactivate the conda environment, then start tmux, then reactivate the environment inside tmux.

  • 2
    Weird solution but works ... – LYu Oct 16 '18 at 17:18
  • That's weird indeed. – ZirconCode Nov 14 '18 at 21:23
  • 1
    I'm upvoting because this is the solution that worked for me, however it is really a far from ideal solution – johnchase Feb 6 at 23:13
1

Running:

conda activate env1

Instead of:

source activate env1

When inside tmux worked for me.

1

The following happens to me after starting a Tmux session (without conda having any active env).

When I first do inside the Tmux session:

conda activate myEnv

I get

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'.

If instead I do:

source deactivate
conda activate myEnv

Everything works just fine. which python points to the correct path.

1

This behaviour is caused by TMux sourcing ~/.profile instead of ~/.bashrc. My ~/.profile is this:

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
    . "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi

You can see that first ~/.bashrc is sourced and then ~/bin and ~/.local/bin are prepended. As I experienced myself, this causes conda to hickup.

The solution would be to comment out the two blocks manipulating PATH in ~/.profile.

0
nano ~/.bash_profile

Add the following lines:

source deactivate env1
source activate env1

worked for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.